views:

103

answers:

1

Hi,

We are using many custom controls by inheriting form the WPFcontrols as the base and customizing it for our need.

However, the memory used by these controls are not released, even after pages using the controls are closed, until the whole application is closed.

As these application has to work for a whole day performance decreases as more and more memory gets held up.

When we profiled our page we found that the controls where not getting collected as there where some binding reference or some borders or brushes etc not getting cleared from that control.

We tried to use the Unload event of the controls to remove the events and some references from the control. This reduced the leak to some extent but this was slowing down closing of the page also the unload event was getting triggered when the control was even collapsed.

Is there any other ways to overcome the leak? Are there any best practices to prevent memory leaks?

Thanks

Arvind

A: 

Are you using any static members? (Especially collections and events)

If so, make sure to remove your controls from them when they're unloaded.

EDIT: I mean that after you're finished with a control (when its page is closed), you should remove it from the visual tree, call Dispose on it, and use a memory profiler to make sure that it is not referenced anywhere.

Use a memory profiler to find out which objects are being leaked and why.

SLaks
I have removed the collections and events in my page and on using profiler i found the majoy leak id from custon controls and if i try to use th eunload event in the controls as i mentioned ablove the closing time becomes very very slow.
Arvind
I used ans profiller to profile my application after profiling and removing the some instance of the controllls are getting removed from memory. But its making the close of the pages very slow as its unloding each of the control in the page as there can be number of control its incresing the closing time.
Arvind