简体   繁体   English

在Windows Phone 8的Silverlight中删除弹出窗口

[英]Delete Popup in Silverlight for Windows Phone 8

I have tested my app for memory usage, and suddenly seen a spike in memory, when I load popups, further it does not seem to go down after I try to close it. 我已经测试了我的应用程序的内存使用率,突然发现加载弹出窗口时内存出现峰值,而且在我尝试关闭它后,它似乎没有消失。

I add the popup from the first pages cs file (the one I navigate away from): 我从第一页的cs文件(我离开的那一个)中添加了弹出窗口:

Popup popup;

if (!SecondScreen.SecondScreenLoaded)
{
    Popup PopupTest = new Popup();
    PopupTest.IsOpen = true;
    LayoutRoot.Children.Add(PopupTest);
}

and when the second page is done I wish to delete the popup, and thus free up memory Therefore I am unsure of how to delete a popup correctly in c#, can anyone please tell me this? 当第二页完成后,我希望删除弹出窗口,从而释放内存,因此我不确定如何在c#中正确删除弹出窗口,有人可以告诉我吗?

i'm never dig app with a native popup on windows phone, maybe you can use coding4fun toolkit to achieve similar things. 我从不使用Windows Phone上的本机弹出窗口来挖掘应用程序,也许您可​​以使用encoding4fun工具包来实现类似的功能。 It contain popup sample, you can look at that control. 它包含弹出示例,您可以查看该控件。

http://coding4fun.codeplex.com/ http://coding4fun.codeplex.com/

在此处输入图片说明在此处输入图片说明

Okay, the thing is you are creating a new Popup object each time your SeconeScreenLoaded is true. 好的,事情是每当SeconeScreenLoaded为true时,您都在创建一个新的Popup对象。

Popup PopupTest = new Popup(); Popup PopupTest = new Popup();

For closing the Popup, my guess is you are using: 对于关闭弹出窗口,我猜您正在使用:

PopupTest.IsOpen = false;

by doing so, you actually change the IsOpen property only, but you do not remove it from memory. 这样,您实际上仅更改了IsOpen属性,但没有将其从内存中删除。 We presume GC will take care of it, but GC will take it in consideration only when its references are not used. 我们假定GC将对其进行处理,但是GC仅在不使用其引用的情况下才考虑它。 So while closing the popup, assign null to the object, to allow GC for collecting it later on. 因此,在关闭弹出窗口时,请将null分配给该对象,以允许GC在以后收集它。

 if(PopupTest!=null && PopupTest.IsOpen = true)
 {
     PopupTest.IsOpen = false;
     PopupTest = null;
 }

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

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