Memory leak problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajithamol

    #1

    Memory leak problem

    What is a memory leak problem?can anyone explain it with eg
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sajithamol
    What is a memory leak problem?can anyone explain it with eg
    For theoretical type questions, you are best to consult a text.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by sajithamol
      What is a memory leak problem?can anyone explain it with eg
      Using Java it's quite difficult to leak memory; here's an obvious example:

      [code=java]
      class Foo {
      private static List<Foo> leak= new ArrayList<Foo>( );
      public Foo() {
      leak.add(this);
      }
      }
      [/code]

      Now keep on allocating Foo objects and keep forgetting about them. The garbage
      collector is very willing to reap them but it can't: the 'leak' list still refers to them all.


      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        Using Java it's quite difficult to leak memory; here's an obvious example:

        [code=java]
        class Foo {
        private static List<Foo> leak= new ArrayList<Foo>( );
        public Foo() {
        leak.add(this);
        }
        }
        [/code]

        Now keep on allocating Foo objects and keep forgetting about them. The garbage
        collector is very willing to reap them but it can't: the 'leak' list still refers to them all.


        kind regards,

        Jos
        Ha, your examples leave a lot to be desired.
        So the Foo objects will only become eligible for collection when the Foo class is unloaded from the JVM?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by r035198x
          Ha, your examples leave a lot to be desired.
          So the Foo objects will only become eligible for collection when the Foo class is unloaded from the JVM?
          Yep, the Foo objects will stay there until the class itself is GC'd.

          kind regards,

          Jos

          Comment

          Working...