Silverlight:在导航到另一页时清除未使用的内存 [英] Silverlight: Clear unused memory on navigating to another page

查看:48
本文介绍了Silverlight:在导航到另一页时清除未使用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的silverlight应用程序有很多页面,并使用导航服务在页面之间导航.页面之一从Web服务获取大量(〜1G)数据.由于垃圾收集不会自动进行,因此当我返回上一页(主页)时,需要清除在该页面中分配的内存. 我尝试覆盖OnNavigatedFrom方法,并尝试将对象引用分配为null并通过GC.Collect()强制进行垃圾回收.但是内存没有被清除.我注意到,如果刷新主页,内存将急剧下降.如何以编程方式执行内存清除.

My silverlight application has many pages and uses Navigation Service to navigate between pages. One of the pages fetches a large amount (~1G) of data from a web service. Since garbage collection is not happening automatically, I need to clear the memory allocated in that page when I go back to the previous page (Home page). I tried overriding OnNavigatedFrom method and tried assigning object references to null and forcing a garbage collection by GC.Collect(). But the memory is not getting cleared. I noticed that if I refresh the Home Page, the memory comes down drastically. How to do memory clearance programatically.

推荐答案

手动调用CG.Collect并不是一个好主意,并且在任何情况下GC.Collect都不能帮助消除内存泄漏.可以释放的内存是通过标准CG行为释放的.也许寻找内存不能自动释放的原因会在某处证明一些错误.

Calling CG.Collect manually is not a good idea, and in any case GC.Collect does not help removing memory leak. Memory that can be free is free by the standard CG behaviour. Maybe looking for the reason that memory is not automatically free will evidentiate some bug somewhere.

这篇关于Silverlight:在导航到另一页时清除未使用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆