Delete Popup in Silverlight for Windows Phone 8
Asked Answered
K

2

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?

Kahn answered 29/12, 2014 at 11:14 Comment(19)
Can you please add some example code?Nadya
I think he just means a regular popup control that you can extract with the treviewhelper. But as for him I cannot see how to confirm a delete of a popup. Popup.isopen does not remove it as I think he refers to. Just some clarification because I hope for a solution too :)Virginium
Yeah thats, what I meantKahn
Maybe this will help? suchan.cz/2013/11/how-to-debug-most-common-memory-leaks-on-wp8Shagbark
If you leave the page, does the memory go down? I am thinking that the popup is instantiated but does not go out of scope until you navigate away from the page.Littleton
That is kind of the problem, at the moment the memory does not go down when I leave a page. Also the popup is made such that it is still running while changing pages, so it is not only part of one page.Kahn
You should avoid using Popups in WP8. Would you consider an alternative solution?Facility
How are you creating this popup? Code would be helpful.Littleton
@JustinXL Why should I avoid using popups and if you have an alternative way I would love to hear it. The main goal of the popup is to hide the pages behind while they are loadingKahn
So you show a popup when a page is loading some data? Wp8 pop ups have serious performance issues, that's why I don't recommend using it.Facility
@JustinXL basically yeah, when I switch from one page to another.Kahn
Take a look at my answer on this one #27623165 I think it does what your looking for, without using pop upsFacility
@JustinXL I see you've linked an example to the answer, but I can't access the example on one drive. It just keeps going around in circles.Kahn
Hmm, weird, I can open it fine. I just re-generated another link onedrive.live.com/… what about this one?Facility
Let us continue this discussion in chat.Facility
Yes you can, but why do you want to delete it? Also, please you show your code for 'startAnimation' too.Facility
@JustinXL "startAnimation" is just the content of the popup, so nevermind that part. I would like to delete it to free up memory when it is not being used, and such that it is not in front of other elements. Is there a way to do this?Kahn
You can just delete that Grid which holds the animation elements inside the frame style.Facility
Remove the popup from the LayoutRoot, and make sure its not in the visual tree, remove any event handler you may have added to the popup properly (beware of delegates), and then set it to null. Should be comfortably GCd. Also, if you use Animation, the storyboards will by default hold, and there by keep a reference to it. It has to be stopped.Himalayas
D
0

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/

enter image description here enter image description here

Dastardly answered 18/4, 2015 at 3:22 Comment(4)
where is it you find the examples?Kahn
Hi @Kahn : you can download it at here and just open the /source folder, it will contain .sln file that you can load it with Visual Studio. Mark mine as answer if you find it helpful, thank you :)Dastardly
I see that there are some projects in the link you've send, but I can't seem to find one where they use popups.Kahn
@Kahn open the link and download entire source, and then navigate to /source/Coding4Fun.Toolkit.Test.WindowsPhone8/Samples/PromptsDastardly
S
0

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;
 }
Shoelace answered 23/7, 2018 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.