Memory leaks and NSAutoreleasepool

Documentation told that sing NSAutorelease pool in background threads are not necessary for now. Note: Since Xamarin.iOS 5.2 you do not have to provide your own NSAutoReleasePool anymore as one will be provided automatically for you. But I spend all day trying to catch the memory leaks from Backgroundworker or Task (yes, tasks are leaking too, I don't know why). That part of code saves my app. Could you please update the documentation (or the library ;)) to refer that it is as necessary as it was?

void HandleDoWork (object sender, DoWorkEventArgs e)
        {
            using (NSAutoreleasePool autoreleasePool = new NSAutoreleasePool())
            {
            //work
            }
        } 

Also have a suspicion that it comes with the new update (since haven't noticed that leaks before) but can't told it with sure.

Posts

  • RolfBjarneKvingeRolfBjarneKvinge USXamarin Team Xamurai

    Currently Xamarin.iOS will wrap every thread's entry point in an autorelease pool, and threadpools are special-cased to wrap every threadpool callback in an autorelease pool too.

    The problem comes with API that caches threads, such as tasks and background workers. They do have an autorelease pool (since every thread gets one), but that pool isn't flushed until the thread exits (which doesn't necessarily happen for a long time, if at all).

    We'll review our API and see if we can improve this for tasks and background workers too.

Sign In or Register to comment.