Detecting memory leaks caused by event handling

Share with us how you use PostSharp, or how you would like to use it.

Detecting memory leaks caused by event handling

Postby WalterLeinert on Thu Jul 12, 2007 11:58 am


In our (quite large, 500000 loc) Windows.Forms client application we had and have a lot of trouble with "memory leaks". A major cause of the memory leaks is missing deregistration of previously registered event handlers. Due to the fact that the object owning the event handler may have references to many other object instances a quit large amout of objects (memory) may be leaking for several actions in the application.
In our application it's caused by programming errors (missing handler deregistration), which are difficult to locate due to the complexity of the application code. I used several commercial tools but none of them showed me the real causes and locations auf the leaks. So i started to work with low level approach: use windbg with sos.dll, do heap statistics/snapshots, find gc roots, ...); i can tell you that this way is a hard way! But i found several leaks with this approach.
After detecting PostSharp i had several ideas what to do with it.
My first task was to implement log4net support similar to the XTrace sample. I have a working first version which will soon be uploaded to the projects area.
My next task is to implement PostSharp based support for detecting memory leaks caused by event handling with an attribute option to fire an exception in the Dispose method of the handler owner object or to automatically unregister the handlers. My first version seems to work! If it really works it will save me many days of memory leak analysis. Currently i'm trying to apply my XEventHandlerDetacher attribute to more complex test programs of our application.
An other idea is to use PostSharp to generate some kind of unit test suites for our application; i will try to write aspects to be able to record information for application test cases which may be replayed many times.

Any comments or suggestions are welcome.
regards, Walter
Walter Leinert
WalterLeinert
 
Posts: 1
Joined: Sat Jan 12, 2008 4:55 pm
Full Name: Walter Leinert

Re: Detecting memory leaks caused by event handling

Postby soren on Sun Feb 24, 2008 5:41 pm

Walter,

Did you succeed in using PostSharp for automitically removing event handlers in the Dispose() method?

If so, would you be interested in sharing your code? I'm looking for possible solutions for that very problem.

Thanks,
Søren
Soren Skovsboll
soren
 
Posts: 15
Joined: Sat Jan 12, 2008 4:55 pm
Full Name: Soren Skovsboll

Re: Detecting memory leaks caused by event handling

Postby gfraiteur on Sun Feb 24, 2008 7:26 pm

Soren,

I suggest you send a private message to Walter, because he surely did not receive a notification since the message dates from before the forum migration.

Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 581
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org


Return to What To Do With PostSharp?


cron