M
moondaddy
I'm writing a WPF app in c# and want to know the best way to get rid of an
object. this is how its created
someclass obj = new someclass();
void CreatObjects()
{
aCollection.Add(obj);
AnotherClass obj2=new AnotherClass(obj);
aNotherCollection.Add(obj2);
)
Now I want to completely get rid of this instance of obj and obj2
void KillObjects(obj, obj2)
{
aCollection.Remove(obj);
aNotherCollection.Remove(obj2);
//Since at this moment obj and obj2 are alive in this method, should I set
the to null like this?
obj=null;
obj2=null;
}
What is the most appropriate what to get rid of obj and obj2?
Thanks.
object. this is how its created
someclass obj = new someclass();
void CreatObjects()
{
aCollection.Add(obj);
AnotherClass obj2=new AnotherClass(obj);
aNotherCollection.Add(obj2);
)
Now I want to completely get rid of this instance of obj and obj2
void KillObjects(obj, obj2)
{
aCollection.Remove(obj);
aNotherCollection.Remove(obj2);
//Since at this moment obj and obj2 are alive in this method, should I set
the to null like this?
obj=null;
obj2=null;
}
What is the most appropriate what to get rid of obj and obj2?
Thanks.