File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

eligible for garbage collection

 
joel garner
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we know which object is eligible for garbage collection ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47310
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you know about it? Have you searched anywhere? Do you have a specific question, for an exam for example?
 
Ulises Pulido
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It is eligible when the object reference get lost and the object is abandoned in the dark side of the heap memory.

By reference I mean that there is no variable pointing to that object. Usually we call them variables but I prefer the term reference because its easier to understand how this things work.

A code sample could be this:

public void method() {
Object a = new Object();
}

after finishing the method no reference will be pointing to the object a was pointing to and that "new Object();" will be abandoned, sad but true.

In case that you return it.

void aMethod() {
Object a = anotherMethod();
}

Object anotherMethod() {
Object b = new Object();
return b;
}

In this case the Object created "new Object()" will have two references pointing to it, first b whose reference is returned in the method and assigned to a, then a will be pointing to that "new Object()" as well, the reference of b dissapears, the aMethod gets executed and the reference from a to "new Object()" dissapears as well and this object gets abandonded and now eligible for garbage collection.


I hope this helps a little.
 
joel garner
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply ulises pulido.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic