Versions Compared

Key

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

...

In this compliant solution, rather than use a dead flag, the programmer assigns null to ArrayList elements that have become irrelevant.:

Code Block
bgColor#ccccff
class DataElement {
   // Dead flag removed

   // Other fields
}

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

// Processing that renders an element irrelevant
// Set the reference to the irrelevant DataElement to null
longLivedList.set(someIndex, null);

...