File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When GC will collect Object instance refered by Static member of some other Class ?

 
Rohan Kayan
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am bit confused regarding the Garbage Collection of object instance which reference is hold by some static member. When will that object be collected by GC ?


Thanks in advance.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we cannot directly say when the garbage collector will destroy the objects
when a running thread using that object is dead, then only there is a possibility that the objects gets destroyed
and also when the objects are null referenced then they can be destroyed
we can call the gc() method but it is merely a request and not the command
 
Simran Dass
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A static member is available as long as the class is loaded. YOur question
has set me thinking.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Object will not get marked for the collection by the GC as long as its reference exists. In case of static it will be loaded till the thread running it is alive. To make it eligible for GC you can call a method which can set the reference to null.

HTH
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic