Re: Two threads two autorelease pools one object?
Re: Two threads two autorelease pools one object?
- Subject: Re: Two threads two autorelease pools one object?
- From: Joseph Kelly <email@hidden>
- Date: Wed, 2 Nov 2005 18:31:54 -0800
On Nov 2, 2005, at 1:50 PM, John C. Randolph wrote:
On Nov 2, 2005, at 12:57 PM, Brian O'Brien wrote:
is it possible that the instance of the object exists
in two auto-release pools at the same time
This is a red herring. Threaded or not, you just have to take care
to balance -retain and -release messages.
Objects don't "exist in auto-release pools", they exist in memory.
An Autorelease pool is nothing more than a delayed message
mechanism. Autorelease pools don't free objects, either. They
send objects a -release message, and the object itself decides
whether it's time to -dealloc.
Even if you have proper memory management, you are not at all
guaranteed this will work in a multithreaded environment (e.g. you
grab an object in one thread and are about retain it, when it gets
released in another thread).
So you need some strategies for thread safety (lots about this on
cocoadev.com): e.g. if you have methods on a class that may be called
by many threads and which manipulate data stored in that object, you
must have some kind of synchronization in place (NSLock or whatever).
joe
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden