I work with the following: VS 2010, .Net 4, WPF and .Net Memory Profiler version 4.6.40.0 Pro. They all run on a 64-bit version of Win7. I use .Net Memory Profiler profiles to track memory leaks and found one that I don't understand, although I seem to have fixed it. We have a control that contains three ContentPresenter objects. If I set the Content property of ContentPresenter objects to null in our cleanup method, then the control does not leak at all. If I do not remove the Content properties, we get a big leak (about 3.5 MB of each test).
The results that I saw in the Google search results did not appear to be directly addressed. The documentation for ContentPresenter didn't help me either. Does anyone here understand why zeroing content recorded a leak? Is there a better way to do the same?
I want to note that one of the ContentPresenter dynamically switches between WindowsFormsHost and BitmapSource to handle airspace issues.
Update: here are the necessary cleaning parts:
First, exclude ContentPresenter
AddressGridPlaceholder.Content = null; AddressFormPlaceholder.Content = null; MapControlPlaceholder.Content = null;
Then clear WindowsFormsHost
if (_hoster != null) { _hoster.Child = null;
source share