Silverlight Memory Leaks
Asked Answered
O

4

6

We have a rather large silverlight 4 application. We are in the process of finding memory leaks in the application and this has turned into a daunting task.

Things have changed completely with this one, for those of you that have seen the original post!

I realised that ANTS memory profiler wasn't showing me the right stuff. That was because the memory leak was not in the managed code, but in the native code. I did fix some issues with ANTS - it is a good tool for managed code memory leaks.

So I found this blog,

http://blogs.msdn.com/b/slperf/archive/2010/08/19/analyzing-silverlight-memory-usage-part-1-obtaining-measurements.aspx

Which was excellent. I used xPerf and xPerfViewer to view the native heap and see what I suspect is the actual memory leak.

So I can see a stack trace which looks like this,

CCoreServices::Draw
    CCoreServices::Tick
    CUElement::Render
        CUIElement::Render
        CUIElement::RenderWithTransform
        CUIElement::RenderVisual
        CUIElement::RenderChildren
            {Repeat of the above in a recursive fashion}

So in this 'Render' method somewhere it allocates about 520 bytes of memory, and as far as I can tell it doesn't free it.

I can also see a method or class called

SDBitmapCreate

is leaking memory too.

Interesting because it seems like I have found something, but I am not really sure what.

Any other suggestions?

Thanks.

Oneway answered 9/12, 2010 at 22:7 Comment(4)
How are you using ANT to detect memory leaks? The only "ANT" I know about (or was able to find via Google) is the Java build tool (ant.apache.org). Is that what you're referring to, or is there some Silverlight ANT tool that I don't know about (and clearly need to)?Adjacency
Never mind, spotted it eventually: red-gate.com/products/dotnet-development/ants-memory-profilerAdjacency
Yep, that is the one. You can filter by namespace, and normally with a memory leak you expect to see classes in your own namespaces that are leaking. That is not the case here, stuff in the silverlight framework is leaking. I am sure we are causing it, but it just makes it harder to spot, and harder to conclude the cause.Oneway
you can use deleaker for search memory leaks....Rodrick
A
6

There's a good tutorial on troubleshooting Silverlight memory leaks here: http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/. It's complicated, and you have to deal with WinDBG commands, but I've found it helpful in the past. Of course, this doesn't answer your question specifically, but it may point you in the right direction.

Adjacency answered 14/12, 2010 at 1:0 Comment(0)
L
4

First Off, I do not know of any memory leak tools for silverlight.

I experienced what I thought where memory leak problems a few weeks ago. Turns out my Silverlight application had rogue children in the canvas.

My issue may not be your issue, but it may get you thinking.

Before I re-populated my list with results from the server, I had to remove all children from appropriate canvas. Clearing the list wasn't enough.:

        for (int i = 0; i < boxDataLabel.Count; i++)
        {
            canvaz.Children.Remove((Label)boxDataLabel[i]);
        }
        boxDataLabel.Clear();

boxDataLabel is a list of type Label.

good luck.

Loireatlantique answered 9/12, 2010 at 22:34 Comment(1)
So why does that create a memory leak? There must be something holding open memory, did you figure out what specifically it was?Oneway
P
2

There is an official memory leak regarding inline DataTemplates in Xaml. You can read a thread about it here: http://forums.silverlight.net/forums/t/171739.aspx.

Microsoft have released a service release (update build is 4.0.50826.0) that should fix the issue: http://timheuer.com/blog/archive/2010/09/01/silverlight-service-release-september-2010-gdr1.aspx

Remember to update the minimum version in the host html file if the service release fix (some of) your problems.

Puncheon answered 15/12, 2010 at 7:5 Comment(1)
The september release fixed some of the problems, but not all of them. The Silverlight team is currently testing a fix that will hopefully be released very soon.Noble
Y
1

If I were in your situation I would try to create a simple test application that demos the leak, just to double-check it is repeatable outside of your actual code. This proves that it isn't a subtle bug in your code. Then, I would post the test app to the MS Silverlight forums, which is monitored by MS folks. If you have an MSDN subscription, or if your company has a support agreement with MS, I would also open up a "ticket" (forget what they actually call them) with MS as well.

Yearlong answered 20/12, 2010 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.