+ 2
Heap and delete
In c++ if I declared a variable or array in the heap.. it's better to dalete them so the computer won't crash after a while ( delete d; ) for example. Do I have to fa the same in JAVA? If yes.. how can I do it?
2 Respostas
+ 2
Thank you
+ 1
In Java, all objects are defined in the heap. But java has a garbage collector to free any memory space that has no reference to it.
So you can tell the garbage collector to collect an object by removing its all references.
For example :
myObject = null;
The garbage collector will collect the object from memory, not immediately but it will.