Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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())

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.


  • 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.