Skip to content
Ameen Abozaid
Planned lessonMID-002-L01

How the JVM allocates objects

  • Lesson 1 of 7
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

explain why allocation is cheap and what it costs later.

Planned topics

  • Most objects are allocated in the young generation by bumping a pointer inside a thread-local allocation buffer (TLAB); no lock needed.
  • Cheap allocation is why short-lived objects are fine in Java.
  • Allocation rate (MB/s) drives how often the GC runs.
  • Very large objects may go straight to a special region or the old generation (collector-specific).
  • OutOfMemoryError: Java heap space means the live set no longer fits, not that allocation is slow.
Draft outline details

Demonstration

java
List<OrderLine> lines = new ArrayList<>();   // 1 object, then N OrderLine objects
for (var item : cart) lines.add(new OrderLine(item));

Check your understanding

What do you measure to know GC pressure?

Show answer

Allocation rate, with GC frequency and pause times.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.