Freeing Memory, Dispose, Class Objects
Posted on 2011-02-15
What is the best way to clear an object of a class? Do I have to clear it from the Memory too? Should I be implementing Dispose()? If so - how?
Lets say I have a simple class. ClassSimple.cs. It contains a few properties and methods. I create an object of this class - CSimpleObj. I use it in the code and at some point I no longer need it. Lets say at a different point I need to use this but I don`t want any of the values from the previous instance. Do I do just a CSimpleObj = null or should I be actually clearing the object from the memory?
How would this effect the performance? If don`t do a cleanup.
private int testInt;
public int TestInt
testInt = value;
SimpleClass CSimpleObj = new SimpleClass();
private void button1_Click(object sender, EventArgs e)
CSimpleObj.TestInt = 45;
//Do something with CSimpleObj
//Lets say, I no longer need the object.
//I want to clear the object
private void button2_Click(object sender, EventArgs e)
//I want an empty object here
//Do something else here