From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Memory management and garbage collection

Memory management and garbage collection - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Memory management and garbage collection

- [Instructor] One of Java's greatest features, is its automatic memory management. Unlike languages like C, C++, Pascal, and others, Java automatically allocates and deallocates memory as needed, as your code is running. It decides where data is stored in memory. For example, in general, local variables and function calls are stored in stack memory, whereas objects and member variables are stored in the heap, but this can differ depending on which version of Java you're using, and how the Java virtual machine is configured. In general though, objects are retained in memory as long as they have valid references. When you create a variable and you assign it an identifier, that is a variable name, that's an anchor that keeps the object in memory. When you release that variable, either because its scope is finished executing, or because you explicitly set that variable to a value of null, that means you've dereferenced the…

Contents