Memory Leaks when using themes

Jul 20, 2009 at 5:24 PM

I'm getting a lot of really bad memory leaks when using themes of any kind (not just these).  I've found references to this issue here (although I think that the summary of the issues is not entirely accurate here):

http://blog.ramondeklein.nl/?p=58

I've created a test project that is a slight modification of the WPF.Themes.Demo project:

http://files.getdropbox.com/u/376992/Theme Leak.zip

It's not exactly production quality, but you get the picture.  If you click on "Add Tab" and subsequently "Remove Tab" the user control that is stuffed in the new tab hangs around rooted in memory by the theme.  You can test this using your favorite memory profiler (I use .NET Memory Profiler, but Ants, Windbg, etc all show the same thing).

Does anyone have any information about avoiding this issue?  It's a bit crazy that this bug exists...  It doesn't appear that the effects use WeakReference (although I can see how that would be crazy hard to implement in a failsafe way).

Any information is helpful.