2

The application which I have developed is an survey application. The Navigation of my application is similar to this Page1 --> Page2 --> Page3 --> Page4 --> Page1. While navigating from one page to another it occupies heap space every time which leads to OOM exception.

I have tried

  • GC.Collect() in OnDisappearing() in every page, It didn't help

  • Used override OnLowMemory() in MainActivity.

    public override void OnLowMemory() 
    {
      GC.Collect ();
    }
    
  • Deleted High res images.

I have used bitmap for button renderer that too within the using block, other than this I haven't used bitmap anywhere else.

How to reduce Heap space usage from growing?? I can't find a way to free heap space. It keeps on increasing which leads to OOM exception. I have asked a similar question here

Can anyone please point out some helpful direction to overcome this??

Community
  • 1
  • 1
Femil Shajin
  • 1,768
  • 6
  • 24
  • 38

1 Answers1

3

The thing is that Forms keep Page instances in memory on the navigation stack. I'd would dispose as much resources I can when next page is navigated into (well, Images are probably the biggest memory hog) and restore them when page comes into the focus again. Garbage collector won't help because everything is still referenced.

That said I think navigation isn't done well enough. One thing you can do is to cast your uservoice and hope that Xamarin will eventually improve it.

UPDATE: I've missed that OP is going to root page at the end, so this answer would apply if user keeps navigating forward.

Miha Markic
  • 3,158
  • 22
  • 28
  • won't **this.Navigation.PopModalAsync ()** removes the instance which has been created??. will Setting every button as null does any help?? – Femil Shajin Sep 30 '14 at 14:01
  • Ops, sorry, I've missed you are going back to root at the end. Try the delayed GC.Collect in that case as I described here http://stackoverflow.com/questions/25198762/is-this-a-memory-leak-in-xamarin-forms/26115245#26115245 – Miha Markic Sep 30 '14 at 14:30
  • Plus there might have been a [bug](https://bugzilla.xamarin.com/show_bug.cgi?id=21995) in <1.2.3 version, according to Jason fixed in 1.2.3-pre3. – Miha Markic Sep 30 '14 at 15:56
  • OOM exception is still thrown after updating to 1.2.3-pre4 . Revisiting the page constantly grows heap space. will try delayed GC and get back on this. – Femil Shajin Oct 01 '14 at 07:25