5

Closed

Memory Leak

description

Pretty bad memory leak while slide show is running. Haven't done any investigation, into what it is. I suspect it's event handlers not being unsubscribed (anonymous handlers are used extensively)
Closed Jul 14, 2009 at 5:34 AM by sbeeler
Fixed in Release 2.1

comments

gdean2323 wrote Apr 15, 2009 at 7:44 AM

There is no Memory profiler capable of profiling Silverlight apps. The recommended work around, as of right now, is to convert the silverlight app to a WPF app and use any .Net memory profiler. After a cursory review of the code, it's almost certainly the anonymous event handler (they are used everywhere). Without retaining a reference to an anonymous delegate, there is no way of unsubscribing it from an event. To fix this issue, will require a fairly exhaustive of search and refactor. Unfortunately I don't have the time to do this right now.

sbeeler wrote Jun 20, 2009 at 8:52 PM

A few comments...

1) I believe I have resolved "the" major memory leak issue in slide.show. See this discussion post for details:
http://slideshow2.codeplex.com/Thread/View.aspx?ThreadId=60173

2) You can, in fact, debug silverlight memory leaks and other such issues without converting it to a WPF. I did, with the help of techniques discussed on Tess Fernandez's blog, "If broken it is, fix it you should" (http://blogs.msdn.com/tess/default.aspx). Agains, see the discussion post for details and specific blog posts that helped in diagnosing this Slide.Show bug.

3) While your suggestion about event handlers not unsubscribing from an event as the source of the problem was right on, it turns out that the use of anonymous delegate event handlers was NOT a significant contributing factor. I actually performed the exhaustive searchand refactor of all anonymous event handlers that you called for, and it didn't improve performance at all. Only after I extended my search to include all event handlers, not just the anonymous ones, did I find the real source of the significant memory leak, which happened to be with actual named event handlers. So thanks for getting me going in the right direction, even if I did get sent a long, winding, and ultimately fruitless dark alley along the way.

Anyway, the fix turns out to actually be pretty simple. Two lines of new code added to SlideViewer, and 4 new lines of code added to the four ITransition classes.

Hope this helps.
--Scott

sbeeler wrote Jul 6, 2009 at 4:36 AM

Fixed in change set 25804. Note that the change set includes additional enhancements and bug fixes as well. Also, note that the change set addresses additional memory leaks not included in the discussion thread.

http://slideshow2.codeplex.com/SourceControl/changeset/view/25804

gdean2323 wrote Jul 6, 2009 at 7:33 AM

Great work Scott. I can't wait to try it out.