When drawing an object in the heap of a stack and heap diagram, the label of the object must be the method signature of the constructor call that created the object (e.g., Pacman()).


In stack and heap diagrams, an object on the heap is labeled like a stack frame of a constructor call


Here is what's right.

Not really.

An object and a constructor’s stack frame are two separate areas of memory used for two separate purposes. They are also labeled differently.

An object on the heap holds the state of the object (the instance variables of the object). In a stack and heap diagram we write the object’s class name next to the object.

A stack frame of a constructor holds the local variables and the parameters used while a constructor is executing. A constructor call is a special kind of method call. A constructor’s stack frame is like a normal method’s stack frame. In a stack and heap diagram we write the constructor’s signature (its name and parameters) next to its stack frame.

The lifetime of an object is potentially much longer than the lifetime of a constructor call. The memory holding an object on the heap is reclaimed when no more reference points to it. The memory holding a constructor’s stack frame is reclaimed when the constructor returns.


Notional Machine


Expressible In

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.