WP7内存泄漏? - 使用列表框数据绑定在包含数据透视项的页面之间导航
我有一个主页,其中有 3 个枢轴项,每个项中都有一个很重的列表框(每个项大约 15Mb,这是正常的吗?)。 当发生某些操作时,我会导航到另一个页面,其中有另一个包含 3 个项目的 Pivot 控件。到目前为止,一切都很好。 当我导航回主页时,我可以看到已用内存有 +2 到 +4mb 的差异。每次我导航到新页面然后返回主页时,总使用内存中就会添加 2-4 mb。我很确定我的代码没有任何问题。即使我的代码中有内存泄漏,也不会那么大。这可能与一些未发布的 UI 元素有关?我在两个页面中手动调用垃圾收集器 onNavieratedFrom 和 onNavigedTo 以防万一,但仍然相同..
这可能是某些控件中的内存泄漏吗?正如我告诉您的,两个页面都包含带有数据绑定列表框的数据透视项,并且数据在运行时不会更改。
谢谢
I have a mainpage where I have 3 pivot items and in each one I have a ListBox which is heavy (Around 15Mb each one, is this normal?).
When some action happens I navigate in another page where I have another Pivot control with 3 items. So far, everything is fine.
When I navigate back to the main page, I can see a difference in used memory +2 to +4mb. And each time I navigate to the new page and then back to main page another 2-4 mb are added to the total used memory. I am pretty sure that there is nothing wrong in my code. Even if there was a memory leak in my code, it wouldn't be so big. This probably has to do with some UI elements that are not released? I manually call the garbage collector onNavigatedFrom and onNavigatedTo in both pages jsut in case, but still the same..
Could this be a memory leak in some control? As I told you, both pages contain pivot items with listboxes with databinding and the data don't change during runtime.
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在页面上使用的任何控件存在泄漏,那么这将导致页面的整个元素树泄漏(因为每个子元素都保留对其父元素的引用,反之亦然)。
即使您的代码是干净的,如果您使用来自存在泄漏的外部方的控件,您的页面也可能会泄漏。在这种情况下,您可以通过在 OnNavigatingFrom() 中从树中删除有问题的元素来减轻影响。这样,只有控制权被泄漏,而不是整个页面。
广告控件目前属于该类别。以下是相关指导:
http://msdn.microsoft.com/en- us/library/gg491975(v=msads.10).aspx
SL Toolkit 中的 ContextMenu 的类似情况(如果您正在使用它)。
If any of the controls you are using on the page has a leak then this will cause the entire element tree of the page to leak (because each child keeps a reference to its parent and vice/versa).
Even if your code is clean, your page can leak if you consume a control from an external party that has a leak. In this case you can mitigate the impact by removing the offending element from your tree in OnNavigatingFrom(). This way only that control is leaked, not the entire page.
The Ad Control currently falls into that category. Here is the guidance for that:
http://msdn.microsoft.com/en-us/library/gg491975(v=msads.10).aspx
Similar story for the ContextMenu from the SL Toolkit, in case you are using that.
讨论位于 http://forums.create.msdn.com/forums/p /76007/466968.aspx 对我的应用程序非常有帮助。
我所做的事情&有效(来自上面的链接):
当我找到更多方法/提示来管理应用程序中的内存时,我'会持续更新这个答案。
Discussion at http://forums.create.msdn.com/forums/p/76007/466968.aspx was very helpful for my apps.
Things I did & worked (from above link):
As I find more ways / tips to manage memory in my apps, I'll keep updating this answer.
抱歉我的英语很差。反正。我有同样的问题。我是这样解决的。
我使用
-=
来处理事件。并修复了它Sorry my English is very bad. Anyway. I have same problem. I solved like this.
I used
-=
for events. And fixed it