简体   繁体   中英

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):

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?

i'm never dig app with a native popup on windows phone, maybe you can use coding4fun toolkit to achieve similar things. It contain popup sample, you can look at that control.

http://coding4fun.codeplex.com/

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

Okay, the thing is you are creating a new Popup object each time your SeconeScreenLoaded is true.

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. We presume GC will take care of it, but GC will take it in consideration only when its references are not used. So while closing the popup, assign null to the object, to allow GC for collecting it later on.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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