aspose file tools*
The moose likes Beginning Java and the fly likes GC doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GC doubt" Watch "GC doubt" New topic
Author

GC doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

K&B 6
Since the method returns the Date object, it will not be eligible for collection even after the method has completed

Then when d2 will be eligible ?


Tell the difficulties that i am difficult.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
When there are no more live references to it.
The reference d in your main method is pointing to d2 after the method call so d2 will only be eligible after the main method has exited or removed all references to it (e.g if the main method sets d to null)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Remember that variables are not garbage collected. Objects are. So it doesn't make sense to talk about whether d2 is eligible or not. The question is whether the object that d2 referenced is eligible. And that will be, as E Armitage says, when there are no other live references. When getDate() exits you're assigning the return value (a reference to that same object) to the d variable, so it's still live until the program ends.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

thanks Matthew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC doubt
 
Similar Threads
Quick Q on String and GC
Garbage Collection (URGENT)!
Garbage Collection
Compiling errata for K&B, SCJP 6