• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

System.gc()

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I deleberately use the statement System.gc()?What will happen to the objects which are not referenced ?
Example :
Vector objVct = new Vector();
objVct.addElement("Java");
objVct = null;
System.gc();
What will happen to vector object(objVct)?
At what point of time the Garbage Collector collects this object ?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
u r calling the garbage collector explicitly [System.gc()].
so that object will be deleted.
regards
o. subramaniam
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are telling the garbage collector
that you would like the garbage collector to run.
You cannot define exactly the time when objects are deleted
from heap memory.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Oliver,
Fundamental of Garbage collection is U can't Force Garbage Collection in Java.
Here after putting ur Object Rference to Null, and by calling System.gc()
ur trying to tell jvm tht u want this object to be Garbage Collected means u want to Delete this Object from Memory Location.
This will be done by a Garbage Collector Daemon Thread but u cannot Give any Guarranty when this will happen.
Still if u have some doubt pls tell me .
thanks
Anurag
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're only suggesting the GC, not telling it. that's why System.gc() is not guaranteed.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anurag,
read my posting exactly and you will see that it is what i said.
You tell the GC that you would LIKE to have it cleaned up, but you don't know when it starts
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the Garbage Collector give more priority to this object ,I mean object of Vector other than the other dereferenced objects ?
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya Oliver,
what u told is correct...
thanks for correcting me.

Does the Garbage Collector give more priority to this object ,I mean object of Vector other than the other dereferenced objects ?"


Regarding above there is nothing like priority for this Vector Object which is Dereferenced here n then System.gc is called.
Its JVM internal Logic n it will do it itself.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic