This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 1999 - System.Net.WebClient generates NSAutoreleaseNoPool() error messages
: System.Net.WebClient generates NSAutoreleaseNoPool() error messages
Status: RESOLVED FIXED
Product: iOS
Classification: Xamarin
Component: Class Libraries
: 5.0
: PC Mac OS
: --- normal
: Untriaged
Assigned To: Sebastien Pouliot
:
:
:
:
  Show dependency treegraph
 
Reported: 2011-11-10 15:09 EST by Dave
Modified: 2012-01-01 04:08 EST (History)
4 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments

Description Dave 2011-11-10 15:09:09 EST
When using System.Net.WebClient to query web services, monotouch complains
about several leaked objects.

Example:

var wc = new WebClient();
wc.UploadStringCompleted += (sender, e) => 
{

};
wc.Headers.Add("Content-Type", "application/json");
wc.UploadStringAsync(address,"POST",data);

this will generate the messages on the console

*** __NSAutoreleaseNoPool(): Object 0xd76edd0 of class NSCFString autoreleased
with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0xd76f330 of class __NSCFDictionary
autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0xd76f4e0 of class __NSCFData autoreleased
with no pool in place - just leaking
Comment 1 Sebastien Pouliot 2011-11-10 17:20:25 EST
I made a quick test and I do not get the messages (on both the simulator and my
iPad). Can you provide a small, self-contained, test case that shows the issue
?

Also state where this occurs (simulator and/or devices), the exact version
you're using (5.0.x) and the iOS version used (simulator or device).
Comment 2 Sebastien Pouliot 2011-11-29 08:22:22 EST
http://stackoverflow.com/q/8309276/220643
^ test case
Comment 3 Sebastien Pouliot 2011-11-29 10:18:44 EST
It looks like the leaks occurs before our `monotouch_thread_start` is called to
set a NSAutoreleasePool.

>OpenReadAsync
objc[62463]: Object 0x9b36cb0 of class __NSCFString autoreleased with no pool
in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[62463]: Object 0x9b363c0 of class __NSCFData autoreleased with no pool in
place - just leaking - break on objc_autoreleaseNoPool() to debug
Thread started: 
Thread started: 
monotouch_thread_start
Thread started: 
Thread started: 
monotouch_thread_start
monotouch_thread_finish
monotouch_thread_start
monotouch_thread_finish
monotouch_thread_start
monotouch_thread_finish
monotouch_thread_start
<OpenReadAsync
Thread finished:
Comment 4 Sebastien Pouliot 2011-11-29 10:22:01 EST
note quite, the Thread is displaying ">OpenReadAsync" so the
monotouch_thread_start should have been earlier - but it seems to be used only
for the threadpool
Comment 5 Sebastien Pouliot 2011-11-29 11:11:01 EST
WebClient uses Thread (not ThreadPool) which don't use an NSAutoreleasePool
instance. Not sure why this did not occur earlier as both Thread and WebClient
have not changed recently (I guess something else changed that triggers the
warning). 

In any case I'm testing code that will ensure all threads will be covered
correctly...
Comment 6 Sebastien Pouliot 2011-11-29 20:22:57 EST
Fixed. It will be in MonoTouch 5.2 (and future 5.1.x beta releases).
I will test it a bit more before backporting it to 5.0.x
Comment 7 Rolf Bjarne Kvinge 2011-12-01 07:45:03 EST
*** Bug 1839 has been marked as a duplicate of this bug. ***
Comment 8 Brian Pautsch 2011-12-31 12:09:30 EST
Will Apple reject the app if it sees those errors? If so, how can I get the
patch?
Comment 9 Brian Pautsch 2011-12-31 12:25:41 EST
I see 5.1 is available, but not 5.2
http://ios.xamarin.com/Releases/MonoTouch_5/MonoTouch_5.1
Comment 10 Brian Pautsch 2011-12-31 12:41:48 EST
I got around it with:

ThreadPool.QueueUserWorkItem(delegate {
    WebClient webClient = new WebClient();
    webClient.DownloadFile(url, fileName);
});
Comment 11 Sebastien Pouliot 2012-01-01 04:08:55 EST
5.2 is not yet released, only the 5.1.x betas are available until then.

This issue has existed for a long time and I never heard about app rejections
related this (in general managed applications tends to leak less than native
counterparts).

Using the ThreadPool will provide a auto-release pool for you. If that fits
your application well (async) then it's a valid workaround.

Note You need to log in before you can comment on or make changes to this bug.