Lecture 32 (Sherriff & Tychonievich) - Under the Hood

Lecture Date: Friday, April 3

With all this talk of objects and pass by reference and allocating memory… did you ever wonder exactly where this stuff was being stored?

There are different types of “memory” in a computer

  • Cache - small, really fast memory that’s attached to the processor - used as “working memory”
  • RAM (Random Access Memory) - holds info about programs currently running - used as “short term memory”
  • Hard disk / SSD - holds data that will persist if the power is cut off - used as “long term memory”

Your programs are .java files, stored on the disk itself. But when they run, the JVM (Java Virtual Machine) requests from the operating system that some space be set aside for your program to run in. This is typically in RAM (although it can vary a little).

Once the program gets going, you have something called the stack and the heap.


Image credit: thenewcircle.com

The stack is where variable pointers go, such as with a complex type. The actual values of the complex type variable is found in the heap.

What happens when a variable no longer points to something in the heap? This is called garbage collection. We’ll take a look at how this works by looking at an example program.