Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: xref OBJ55-JG

Setting local reference variables to null to "help the garbage collector"€ is unnecessary. It adds clutter to the code and can make maintenance difficult. Java just-in-time compilers (JITs) can perform an equivalent liveness analysis; in fact, most implementations do so. A related bad practice is use of a finalizer to null out references. See MET12-J. Do not use finalizers for additional details.

This guideline applies specifically to local variables. For a case where explicitly erasing objects is useful, see OBJ55-JG. Remove short-lived objects from long-lived container objects.

Noncompliant Code Example

...