In the constructor of my class, I map the current object (this), along with its key (a string entered as a parameter in the constructor) into a static LinkedHashMap so I can reference the object by the string anywhere I might need it later.
Here's the code (if it helps):
public class DataEntry {
/** Internal global list of DataEntry objects. */
private static LinkedHashMap _INTERNAL_LIST;
/** The data entry's name. */
private String NAME;
/** The value this data entry represents. */
private Object VALUE;
/** Defines a DataEntry object with a name and a value. */
public DataEntry( String name, Object value )
{
if( _INTERNAL_LIST == null )
{
_INTERNAL_LIST = new LinkedHashMap();
}
_INTERNAL_LIST.put( name, this );
NAME = name;
VALUE = value;
}
}
The problem? Instances of this class won't get garbage collected when I'm done using them.
I'm just curious if there's a way to have instances of this class clean themselves up when I'm done using them without having to manually call a Remove() method or something each time (to remove its reference in the internal LinkedHashMap when I'm no longer using them, I mean).