Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java Language
Expertise: Beginner
Mar 6, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Destroying Objects

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

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.



Thanks for your registration, follow us on our social networks to keep up-to-date