From the course: Java 8+ Essential Training: Syntax and Structure
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 - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
Memory management and garbage collection
- [Instructor] Even though Java is a compiled and statically-typed language, it manages memory for you, unlike languages like C, C++, Pascal, and others. In Java, you don't have to explicitly allocate and deallocate memory whenever you create or destroy an object. The garbage collector is a major feature of the Java Virtual Machine. I'm going to describe how the garbage collector works and how little attention you as the programmer usually need to give it. When you create a variable that references a complex object, that variable is stored in the fastest available memory, but the object it references is always stored in heap memory. There are two types of memory, stack and heap. The stack memory is somewhat faster, heap a little bit slower, but still more dynamic. When you create primitive variables, depending on their context, they might be stored in stack or heap. But complex objects are always stored in heap. As long as any variable references an object in memory, that object will…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.