Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: made some minor edits, please review

...

Code Block
bgColor#FFCCCC
class DataElement {
   private boolean dead = false;
   // other fields

   public boolean isDead() { return dead; }
   public void killMe() { dead = true; }
}

// elsewhere
ArrayList longLivedList = new ArrayList<DataElement>(...);

// processing that renders an element irrelevant
// Kill the element that is now irrelevant
longLivedList.get(someIndex).killMe();

The garbage collector will be unable to cannot collect the dead DataElement object until it becomes unreferenced. Note that all methods that operate on objects of class DataElement must check whether the instance in hand is " dead."

Compliant Solution (Set reference to null)

In this compliant solution, the programmer no longer uses rather than use a dead flag. Rather, he the programmer assigns null to {ArrayList}} elements that have become irrelevant.

...

Note that all code that operates on the longLivedList must now check for list entries that are null.

...

Wiki Markup
When using this pattern, the NULLNull object must be a singleton and consequently must be final. It may be either public or private, depending on the overall design of the {{DataElement}} class. The state of the NULLNull object should be immutable after creation; this can be enforced either by use of final fields or by explicit code in the methods of the {{DataElement}} class. See \[[Grand 2002|AA. Bibliography#Grand 02]\] "Chapter 8, Behavioral patterns, the Null Object" for additional information on this design pattern.

...

OBJ13-EX1: System.gc() may be invoked as a last resort in a catch block that is attempting to recover from an OutOfMemoryError.

Risk Assessment

Misusing some garbage collection utilities can cause Denial Of Service severe performance degradation resulting in a denial of service (DoS) related issues and severe performance degradation.

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

OBJ11-J

low

likely

high

P3

L3

...