H
Huey
This is a total newbie question so please bear with me. I need some
clarification to my understanding.
I understand the garbage collector is responsible for destroying objects and
by default we don't know when that is going to happen. If, for example, I
have a Chair object and one of the properties is a Person object. If the
Person object is not null it means a person is occupying this chair. (I can
fx set Chair.Person.Name="Joe Bloggs"
When I then want to remove the person from the chair, I could set
Chair.Person=null;
But is this a good design? Can I trust the Person object is destroyed when
coding
if(Chair.Person==null)
{
// seat is now vacant
}
or will the workings of the GC give this an unpredictable result.
In other words, should I control whether a person is occupying a seat in
another way?
Thanks.
clarification to my understanding.
I understand the garbage collector is responsible for destroying objects and
by default we don't know when that is going to happen. If, for example, I
have a Chair object and one of the properties is a Person object. If the
Person object is not null it means a person is occupying this chair. (I can
fx set Chair.Person.Name="Joe Bloggs"
When I then want to remove the person from the chair, I could set
Chair.Person=null;
But is this a good design? Can I trust the Person object is destroyed when
coding
if(Chair.Person==null)
{
// seat is now vacant
}
or will the workings of the GC give this an unpredictable result.
In other words, should I control whether a person is occupying a seat in
another way?
Thanks.