My control is being kept alive because of command it is bound to. How can I break this reference? This is causing a major memory leak in my application. The control is inside of a DataTemplate so I have no direct access to it.
Here is my ANTS memory profile:
How on earth do I break this connection?
Though I incorporated
WeakEventListener
, I discovered that my problem was with the control I was using to wrap up my images. I was hooking it up toDownloadProgress
,ImageOpened
, andImageFailed
events and never unhooked them. My thinking was that nothing else in my code was touching theBitmapImage
objects so they would be garbage collected with the control. This, it sees, is not the case. TheBitmapImage
objects were referenced by a static member (and therefore a GC root) deep within Microsoft's code called "ManagedPeerTable.PeggedManagedPeersWithRefs". It was so deep that a Google search returned only five results for it. Now I suppose there will be six.