Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"__________ for Java" as "free in C" or "delete in C++"

Tags:

java

What keyword or function is used in Java to release memory?

like image 901
arup saha Avatar asked Dec 08 '22 02:12

arup saha


2 Answers

You don't release memory in Java. it is garbage collected by the JVM.

Objects are created by Java's "new" operator, and memory for new objects is allocated on the heap at run time. Garbage collection is the process of automatically freeing objects that are no longer referenced by the program.

like image 59
Byron Whitlock Avatar answered Dec 11 '22 20:12

Byron Whitlock


Java is garbage collected, which means that you don't explicitly release memory. Instead, the JVM automatically frees memory when it is no longer referenced. You explicitly de-reference something by setting any variables you had that were referencing it to null, but that doesn't necessarily guarantee it'll be garbage-collected immediately.

like image 36
Amber Avatar answered Dec 11 '22 19:12

Amber