Issue
I have Xamarin.Forms application running on UWP that has a page that contains a third party component. I have navigated to the page and navigated away, disposing of the page and all of the components within it.
I call the GC.Collect()
and expect the page and its controls to no longer be in memory. but I found that the page was still in memory and at the bottom of the memory leak was the third party component with a Depenent Handle (or event handler I assume):
After reporting this to the third party they respond with the following:
I have discussed this with the dev team and according to them releasing the controls from the visual tree is performed by the platform and it is not performed immediately after removing it, so calling the garbage collector and checking if it is still in memory doesn't mean it is leaking. the platform could release it at another time.
Now I think the above statement isnt true... but I can't find anything on the internet or in the MS docs to disprove it.
to my knowledge if I dispose of a page and all its contents and call the garbage collector, the page and all its controls should be gone from memory
Is this correct?
Solution
So I think my statement is correct:
If you navigate to and from a page and dispose of the page and all its components and call
GC.Collect()
. Then the page and all its components should be gone from memory.
I found this article that did exactly that: https://www.xamarinhelp.com/tracking-memory-leaks-xamarin-profiler/
"You will want to press the snapshot button once your app has loaded, to get a baseline. Then, lets navigate to the second page, and press back again. I would create another snapshot now. Then I might keep on doing the navigation a few more times and pressing snapshot again."
"In our example, we went back and forth between the MainPage and SecondPage. We should only see one new SecondPage at most between snapshots, but here we see that multiple were created and are still active."
Answered By - User1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.