Forum Xamarin.iOS

MonoTouch.Dialog memory leak

shawnshawn CAMember

There seems to be a consistent memory leak in MonoTouch.Dialog. It's noticeable under iOS 6 and iOS 7. Using the standard MTD sample program, all I did was go back and forth between the main screen and the first sub-element (iPhone Settings Sample). I did this dozens of times. Using the Instruments program, I saw the Real Mem value continually increase until a garbage collection event occurred. The Real Mem value would then decrease by quite a bit, but never back down to where it started. After repeating this scenario several times, the program was consuming tens of megabytes more memory than when it started, even after being left alone for an hour. And it's much worse if you go back and forth with a web view element. In that case, the program will consume hundreds of megabytes of extra memory and eventually be killed by the OS.

Can anybody confirm what I'm seeing?

Posts

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai
    edited October 2013

    @Shawn,

    Interesting. Are you able to pinpoint some problem areas using instruments? I have not looked at the MT.D sample app in a while, but usually the sample programs are not written with "best practice" code in mind. So, while the sample may have leaks, it might not be related to MT.D. Are you seeing problems in some other app using MT.D that led you to test this? I have been using MT.D for a while and have not had any known issues like this, so I would be curious if there is something I should be fixing too!

  • shawnshawn CAMember

    Our MT.D code has been in use for a couple of years now with no particular problems. However, one of our testers found the memory leak when he was going in and out of our settings pages. I then used the MT.D sample program to double check our program, and it showed the same memory leak that we're seeing with our code. Both sets of code are extremely simple, and I don't see anything in either program that looks like a memory leak, so it doesn't look like it's a "best practice" issue.

    That said, the one thing I did notice is this: each time you go to a sub-element, a new view controller is created and pushed onto the navigation bar. When the user returns from the sub-element view, that view controller is popped from the navigation bar, but its Dispose() method is not called directly, which in turn means that Dispose() is not being called for root, tableView, searchBar, or refreshView. This could well be the root of the memory leak, but I haven't had time to test it any further.

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @shawn,

    Thanks for the follow up. I'll have to take a look at what your suggesting and find out how that might be effecting my app. Thanks for sharing!

    I would be curious if you do find a concrete source of the problem you are seeing.

Sign In or Register to comment.