Garbage Collection

Garbage Collection

Is it possible to preserve an object from garbagecollection (to live as long as the applet)?

Yes, it is possible to preserve an object from garbage collection andlive as long as an applet. To do this you merely have to create a membervariable in the applet that references the object you want to preserve.So long as the applet lives, it will maintain a reference to the object,which will prevent the garbage collector from reclaiming the object.However, as soon as the applet dies and no other object references theapplet, then both the applet and the object in question will becomeeligible for garbage collection. Usually the browser runtime will maintaina special reference to an applet while it is active, preventing it frombeing garbage collected.


Share the Post: