Memory Leaks in Silverlight

2 posts, 0 answers
  1. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 23 Nov 2009 Link to this post


    I know my question is not RadControl related, but I still hope you can help me with my issue.

    I have a main silverlight solution, composed of several small silverlight project, which are different UserControl that are being called at different times in the runtime of the application.

    When I'm calling more than one time one of these usercontrols, my solution crashes, telling me that the visual tree already contains one particular framework element (in this case, a storyboard).

    Si I've been looking around, and I supposed it might be caused by the fact that the garbage collector, when the object is destroyed, doesn't collect it and then, doesn't clear the visual tree.

    So I started debbuging the solution using WinDbg and sos.dll, and I saw after I remove the object that some reference were still there.

    I've tried to implement the IDisposable interface in all the classes of the usercontrol and manage to remove a lot of memory leaks, but there are two types of leak I cannot get rid of.

    Here's the result in WinDbg of the command dumpheap -stat -type

    032a285c        2           24 SilverApp.DetailArticle+<>c__DisplayClass3
    03070d98        2           24 SilverApp.Converters.ImageLinkConverter
    0307ec4c        1           32 SilverApp.LigneCommandeValideeEventHandler
    03070e6c        3           36 SilverApp.Converters.MoneyConverter
    03072c24        1          116 SilverApp.Adresse
    03075f9c        4          128 SilverApp.LigneCommandeSelectionneeEventHandler
    03075d84        1          140 SilverApp.dgCategorieCommande
    03070bb4        1          140 SilverApp.Panier
    030702c4        1          168 SilverApp.EnteteCommande
    030707a4        1          228 SilverApp.DetailArticle
    02b4eb90        1          300 SilverApp.Page

    Both converters (ImageLinkConverter and MoneyConverter) are not destroyed,and the custom EventHandlers aren'r either.

    I think I've tried everything, from GC.Collect to WeakReferences, I don't seem to be able to remove those references and clear completely my SilverApp object from the memory.

    So my question is, does anyone know of a way to remove all that crap from the memory and make sure a Usercontrol is cleared from the visual tree as well when destroyed (Dispose method, null affectation, ClearValue method...)

    Thanks for reading


  2. Vladimir Milev
    Vladimir Milev avatar
    1061 posts

    Posted 27 Nov 2009 Link to this post

    Hi Subileau Pascal,

    From the dump doesn't look like you have a lot of objects left. Maybe those are roots of your application and need to be there since they are still in use? Generally speaking you should check using !gcroot how each object is "rooted" away from garbage collection.  You can check this guide for more info: or my blog post.

    Good luck.

    All the best,
    Vladimir Milev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top