开发者

Silverlight memories

Why so much memory in Silverlight?

Data:

I am having many check boxes and 开发者_如何学运维others on USER INTERFACE sometimes. As matter of course, I am removing check boxes and other controls from visuals, but the memory usage of Silverlight always increases; it never decreases.

How do I ensure memory is released?

Is this a problem with garbage collection? How do I find root of all remaining objects with no reference that are not yet collected?

I can provide more data if it is needed.


The most common cause for run away memory is not detaching event handlers from elements that have been removed from the object tree.

Something often evades notice is that instance level fields (including the delegates that implement events) on the application object and the MainPage (or whatever is being use as the RootVisual) are as good as static fields since they typically live as long as the app does.

Hence an innocent looking:-

btn.Click += btn_myClickHandler;

in the code of the main page can lead to a memory leak if btn is removed from the UI without a corresponding:-

btn.Click -= btn_myClickHandler;


The memory management engine that Silverlight uses is similar to the one that the CLR uses for WPF and other traditional .NET applications. It is based on garbage collection and if you maintain references to objects, even accidentally, that prevents them from being garbage collected, then memory consumption will continue to increase.

If you have this problem in your Silverlight application you can look around for leaks or you can try to use tools to look for leaks and to find where most of the memory is being allocated. Probably the quickest way is with a memory profiler. Unfortunately there are not a lot of memory profilers that work with Silverlight but the ANTS profiler, which has a free trial version, supposedly does:

  • ANTS Memory Profiler 7.0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜