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.