I derived a very simple class from EventArgs,IDisposable:
Now I am tyring to see the effect that declaring many of these classes will have on memory...Code:public class GoodEventArgs : EventArgs,IDisposable { public static int m_nDivisor; public readonly int m_nQuotient; public GoodEventArgs(int nQuotient) { //Is this the memory leak? m_nQuotient = nQuotient; } public void Dispose() { //I only have Value Types, should I be doing anything in here? } }
My memory usage for my app in task manager increases from 13,488K to 13,604K when I run through this for loop and I never get the memory back to 13,488. So it seems that I am leaking a little bit of memory each time I go through the for loop.Code:GoodEventArgs.m_nDivisor = 2; for (int index = 0; index <= 99; index++) { if (index % GoodEventArgs.m_nDivisor == 0) { //Or is this the memory leak? using (GoodEventArgs newDivisibleEvent = new GoodEventArgs(index)) { OnGoodEvent(newDivisibleEvent); } } }
The only member variable of GoodEventArgs is of Type int. So Its not like I can set that to null and claim the memory back in the Dispose() fxn. How can I claim this memory back? Maybe the memory is allocated to the new GoodEventArgs and not the GoodEventArgs.m_nQuotient? In which case, how can I claim back the memory used by my GoodEventArgs refernce type?




Reply With Quote