简体   繁体   English

Silverlight:如何从内存中卸载(处置)图像?

[英]Silverlight: How to unload (dispose) an image from memory?

I have an image control that displays a large jpg file and takes around 50mb of memory. 我有一个图像控件,显示一个大的jpg文件,占用大约50mb的内存。 How do I dispose of this control when it is no longer needed? 如果不再需要此控件,该如何处理? I tried removing it from the parent container, setting it to null and chaning its Source property to null, but the memory usage still stays the same... Any suggestions will be highly appreciated! 我尝试将其从父容器中删除,将其设置为null并将其Source属性转换为null,但内存使用情况仍保持不变...任何建议都将受到高度赞赏!

I have finally found the answer to my question. 我终于找到了问题的答案。 The problem was in a memory leak bug in Silverlight. 问题出在Silverlight中的内存泄漏错误中。 I found the workaround for this problem here: http://blogs.msdn.com/silverlight_sdk/pages/silverlight-bugs-and-workarounds.aspx 我在这里找到了解决这个问题的方法: http//blogs.msdn.com/silverlight_sdk/pages/silverlight-bugs-and-workarounds.aspx

Memory Leak when you Dynamically add and remove Images 动态添加和删除图像时内存泄漏

Workaround: When dynamically adding or removing BitmapImages from an application (aka adding/removing from the tree), you should set Image.Source = null before removing the Image element from the tree. 解决方法:从应用程序动态添加或删除BitmapImages(也就是从树中添加/删除)时,应在从树中删除Image元素之前设置Image.Source = null。 This will make the BitmapImage eligible for garbage collection. 这将使BitmapImage符合垃圾回收的条件。 Bug Status: Active bug. 错误状态:活动错误。 * *

Thanks everyone for the suggestions! 谢谢大家的建议!

I think this is an edge case problem with Silverlight due to the reliance on garbage collection. 我认为这是Silverlight的一个边缘案例问题,因为它依赖于垃圾收集。 Unfortunately if you are instantiating a lot of objects (and I do mean a lot) then you will get performance degredation (even if you free everything up properly and/or Dispose() of everything) because the GC just doesn't keep up and we don't have the resources to throw around like we do in a "normal" application. 不幸的是,如果你要实例化很多对象(我的确意味着很多)那么你将获得性能降级(即使你正确地释放所有东西和/或Dispose()所有东西)因为GC不能跟上并且我们没有像在“普通”应用程序中那样抛出资源。

Are you getting an issue, or just memory watching? 你有问题,还是记忆?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM