none
MemoryLeak when using Bing Maps control? RRS feed

  • Question

  • I'm building a simple XAML/C# app. I noticed when I navigate through pages, the memory size of the app exceeds 500MB. specially pages with more UI controls (specially the bing maps control). It's like Metro style apps dont use Garbage Collector.

    I also tried to dispose all objects I use and set them as null once I finish using them. but still, that didnt help that much.

    Calling Dispose from the Bing Map control saves a lot of memory space. But I dont know where to call it from. I tried the Unloaded, OnNavigatedFrom. but the app keeps crashing once I press back. This is my code:

    (myMap.Parent as Grid).Children.Remove(myMap);
    (myMap2.Parent as Grid).Children.Remove(myMap2);
    myMap.Dispose();
    myMap2.Dispose();




    Thursday, May 10, 2012 10:30 AM

Answers

  • The ref count will never go to zero (known bug on the consumer preview build) and Dispose may cause a crash if the control is still referenced by xaml anywhere. You may be able to work around this issue by making sure all references to a Map instance are removed from the UI tree, waiting a frame to make sure xaml is done with it and then disposing.
    Thursday, May 10, 2012 5:27 PM

All replies

  • The ref count will never go to zero (known bug on the consumer preview build) and Dispose may cause a crash if the control is still referenced by xaml anywhere. You may be able to work around this issue by making sure all references to a Map instance are removed from the UI tree, waiting a frame to make sure xaml is done with it and then disposing.
    Thursday, May 10, 2012 5:27 PM
  • Hello, I'm having the same problema in the Consumer preview, I have to call the .Dispose() method from the Unload event of the page in order to get rid of the memory leak.
    Wednesday, May 16, 2012 7:33 PM