Versions Compared

Key

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

...

When a superclass defines a finalize() method, make sure to decouple the objects that can be immediately garbage collected from those that must depend on the finalizer. This compliant solution ensures that the buffer can be reclaimed as soon as the object becomes unreachable.

Code Block
bgColor#ccccff
Classclass MyFrame {
  private JFrame frame;
  private byte[] buffer = new byte[16 * 1024 * 1024]; // now decoupled
}

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2e8d2a6b2337081a-65b587f6-4e2145bd-a4bbad7e-a9d13005e499125bec2810d4"><ac:plain-text-body><![CDATA[

[[MITRE 2009

AA. Bibliography#MITRE 09]]

[CWE-586

http://cwe.mitre.org/data/definitions/586.html] "Explicit Call to Finalize()" and [CWE-583

http://cwe.mitre.org/data/definitions/583.html] "finalize() Method Declared Public"

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

 

CWE-568 "finalize() Method Without super.finalize()"

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a8f32a99236f5e00-a252b047-444148ee-a007864d-a4e5883ce9b5a0be32c350f8"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

[finalize()

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#finalize()]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9194f7718ad267c9-41dd9d2e-43dc4da3-9273a3e5-b6b3f3123ea56a0e3927c9ba"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. Bibliography#Bloch 08]]

Item 7, Avoid finalizers

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="44da0c6024ace780-69028331-4b534ae0-9ebea78f-d4830ebc147e03edfad25f8e"><ac:plain-text-body><![CDATA[

[[Boehm 2005

AA. Bibliography#Boehm 05]]

 

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3aec9dd421408f1e-25058370-46b9481b-a0c8b9d8-2f296cc03dfee1eaad0ac072"><ac:plain-text-body><![CDATA[

[[Coomes 2007

AA. Bibliography#Coomes 07]]

"Sneaky" Memory Retention

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7c6746e44dbe359d-6e7e74dc-47784591-bc63800b-3fa459acdb8d2dd52e04a36a"><ac:plain-text-body><![CDATA[

[[Darwin 2004

AA. Bibliography#Darwin 04]]

Section 9.5, The Finalize Method

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ab6e8b881bb21f59-c84f5772-4eaa4db0-bbf485bf-741a3f35727c548d468acc96"><ac:plain-text-body><![CDATA[

[[Flanagan 2005

AA. Bibliography#Flanagan 05]]

Section 3.3, Destroying and Finalizing Objects

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0ff1762b322d643a-4d45d712-41c046b7-bde4b929-f4183f41060c681051b80932"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

Section 12.6, Finalization of Class Instances

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

...