Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage Collection

 
praveen parlapalli
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in Garbage Collection. What I understood about GC is "when an object is not reachable by any valid reference the object will be eligible for Garbage Collection" .My doubt is if I have a valid reference to an object and I dont use it will it ever be eligible for GC or will it be eligible after sometime .

Let's say I have mistakenly created an arraylist with "values" as reference variable(List values =new ArrayList() and I dont use in my system. When will "values" be eligible for Garbage collection
 
Henry Wong
author
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An instance is GC'ed when it is no longer reachable from a "root". If an object is reachable from an array list that is, in turn, not reachable, then the object is not reachable. If this array list is in a class variable, that the classloader will not remove, then it will not be GC'ed. Even if your system doesn't use the variable.

Henry
 
Amir Iqbal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well my friend.there is little bit change in your concept. brother, actually garbage collection is a very good feature of java language and by this feature the memory utilization can be well managed.
Now the main concept of GC is if you have created an object but that object do not have its refrence, than that object is eligible for GC. for example,
you have a clss name as MyClass. and instead of making its object like MyClass mc=new MyClass(); you created its object as:"new myclass();"
than that meanz the object created by the second way is eligible for GC because it doesnot have any refrence......
if you find something more abt it then please do tell me. i will appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic