Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Applets
Expertise: Beginner
Feb 26, 1998

Garbage Collection

Question:
Is it possible to preserve an object from garbage collection (to live as long as the applet)?

Answer:
Yes, it is possible to preserve an object from garbage collection and live as long as an applet. To do this you merely have to create a member variable 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 the applet, then both the applet and the object in question will become eligible for garbage collection. Usually the browser runtime will maintain a special reference to an applet while it is active, preventing it from being garbage collected.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap