Threading and Pooling

MonoTouch’er! Does this pattern looks familiar ?

var t = new Thread (delegate () {
	using (var pool = new NSAutoreleasePool ()) {
		// long, arduous task to be completed
	}
});
t.Start ();

If not then maybe you’re seeing things like this ?

objc[20283]: Object 0x9c08110 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[20283]: Object 0x9c07840 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

In any case rejoice! as it will soon (once MonoTouch 5.2 is released) be a thing of the past and you’ll be able to forget this little detail – just like you already can with when using the ThreadPool.

var t = new Thread (delegate () {
	// long, less-arduous task to be completed
});
t.Start ();

The main motivation behind this change was to fix every case where Thread is being used inside the Mono base class libraries (BCL) – but it also has the indirect and nice effect of making the source code cleaner (imho) and more easily shareable between different .NET platforms.

There are a few other places where I think we could do better between iOS and the BCL supplied with MonoTouch. But you likely have some favourite too 🙂 your feedback on them is much welcome.

Advertisements

About spouliot

Xamarin Hacker, Mono Contributor, Open Source Enthusiast with strong interests in Code Analysis, Cryptography and Security. Presently working on MonoTouch, previous projects were Moonlight and libgdiplus and a lot of the cryptographic work done on Mono.
This entry was posted in mono, monotouch, xamarin. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s