Login | Register   
LinkedIn
Google+
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: Java Language
Expertise: Beginner
Mar 6, 2000

Destroying Objects

Question:
In VB, you can release the object's memory with the following:
set object = nothing
How do you accomplish the same thing in Java?

Answer:
The analogous way of doing this is to set an object to null:

object = null;
However, this does not immediately free the memory used by the class instance. This only reduces the number of references to the memory by one. If this action causes the number of references to go down to zero, then the memory becomes eligible for garbage collection. The garbage collector does not immediately reclaim the memory, but most JVMs will free the memory shortly afterward. You can ask the garbage collector to run using System.gc(), which does not provide any guarantee regarding when it will run, but often causes the garbage collector to run immediately.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap