• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection of static data

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can anybody please tell me when does static data are Garbage Collected ??

Thanks in advance .
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First of all, please clarify what you mean by "static data"? The last time someone asked a question similar to this, my assumptions were wrong -- the question was about something else.


Now... assuming that this is about objects being referenced by static variables.... Objects are just objects. They can be referenced by instance variables. They can be referenced by static variables. And at the same time. And when none of those reachable variables reference the object anymore, the object will be eligible for GC.

Henry
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry ,

Let me make your my query more clear .

For example consider an Utility class in a web application that returns a Session :



My question if i close the session on the implementation class will this be eligible for Garbage collection
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question if i close the session on the implementation class will this be eligible for Garbage collection


Objects are eligibile for garbage collection when the object is no longer reachable ... period.

The garbage collector doesn't have a concept of sessions or closing of them. The session object will be GC'ed when it is no longer reachable -- this means that the session factory must get rid of any references to it. And any code that has a reference to the object returned by the method must no longer reference it. Anything that is reachable, having a reference to the session object, will make the object not eligible to GC.

Henry
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry , it was nice explanation .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic