Chapter 6. Recycling

Regardless of continuous improvements in memory management speed, allocating and eventually discarding objects (via garbage collection) will always impose a nontrivial performance cost on Java programs. Moreover, object creation itself imposes an additional cost of properly setting the initial state of the constructed object via a constructor invocation. Object construction triggers the following steps [LY97]:

  1. Sufficient memory is allocated to hold all instance variables (object members) as well as those of each superclass.

  2. All instance variables of this class and those of each superclass are initialized to their default values (numeric variables to 0, boolean to false, reference types to null.)

  3. Proper values are assigned to ...

Get Java™ Performance and Scalability, Volume 1: Server-Side Programming Techniques now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.