Local database reading edition
Helping the Java Garbage Collector
Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.
Forum index · Java - Tips Of The Day
Opening post
Asha · 2001-04-06 13:53:50
When you create an object in Java, such as in the following code:
<pre id=code><font face=courier size=2 id=code>MyClass b = new MyClass(); </font id=code></pre id=code>
Java creates a new MyClass object in memory and sets the value of variable b so that it points to this object on the heap. It also sets a reference count to the object. When you are finished with the object set the reference variable to null. This reduces the reference count and, when the reference count reaches zero, the object's memory can be reclaimed by Java's garbage collector.
Remember to set unused object references to null: <pre id=code><font face=courier size=2 id=code>b = null;</font id=code></pre id=code>to help out the Java garbage collector.
I have read that If you do not make a unused object reference to null then Garbage Collector may take 4 invocation run to collect the object But If you set the reference to null then GC may collect in the first invocation itself.
Source notes
MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 78