Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

With generational GCs, use of short-lived immutable objects is generally more efficient than use of long-lived mutable objects, such as object pools. Avoiding object pools improves the GC’s efficiency. Object pools bring additional costs and risks: they can create synchronization problems and can require explicit management of deallocations, possibly creating problems with dangling pointers. Further, determining the correct amount of memory to reserve for an object pool can be difficult, especially for mission-critical code. Use of long-lived mutable objects remains appropriate when allocation of objects is particularly expensive (for example, when performing multiple joins across databases). Similarly, object pools are an appropriate design choice when the objects represent scarce resources, such as thread pools and database connections.

The rules FIO00-J. Defensively copy mutable inputs and mutable internal components and OBJ09-J. Defensively copy private mutable class members before returning their references promote garbage-collection-friendly code.

...

Setting local reference variables to null to “help the garbage collector” is unnecessary. It adds clutter to the code and can introduce subtle bugs. Java just-in-time compilers (JITs) can perform an equivalent liveness analysis; in fact, most implementations do this. A related bad practice is use of a finalizer to null out references. See rule MET18-J. Avoid using finalizers for additional details.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b0eee822ff6eb803-ae88d4ba-4a354fac-b7f28961-874f83022f65dcadbe8a4371"><ac:plain-text-body><![CDATA[

[[API 2006

AA. References#API 06]]

Class System

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="71dd06c3bad3c3b1-f0d48519-4fbc4948-97a38e71-77fc1b3f79ce966769e3fff8"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. References#Bloch 08]]

Item 6: “Eliminate obsolete object references”

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="291f81ee94083d55-390e9ac0-41d14776-b95b93c2-e5f99bb3c638f57741900e6b"><ac:plain-text-body><![CDATA[

[[Coomes 2007

AA. References#Coomes 07]]

Garbage Collection Concepts and Programming Tips

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="35f61c67a10813fb-96ebe8be-46f941ac-b11097d4-9074244e20bf3f5eb55d7eff"><ac:plain-text-body><![CDATA[

[[Goetz 2004

AA. References#Goetz 04]]

Java theory and practice: Garbage collection and performance

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9c8af4da30350a60-95c8ee89-41d44731-a4fbbac3-7811f19fe49398b851ca92e1"><ac:plain-text-body><![CDATA[

[[Lo 2005

AA. References#Lo 05]]

Security Issues in Garbage Collection

]]></ac:plain-text-body></ac:structured-macro>

...