dealloc on Background Thread

Posted by Mark Brackett on Stack Overflow See other posts from Stack Overflow or by Mark Brackett
Published on 2010-04-30T16:47:28Z Indexed on 2010/04/30 17:07 UTC
Read the original article Hit count: 285

Is it an error to call dealloc on a UIViewController from a background thread? It seems that UITextView (can?) eventually call _WebTryThreadLock which results in:

bool _WebTryThreadLock(bool): Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread.

Background: I have a subclassed NSOperation that takes a selector and a target object to notify.

-(id)initWithTarget:(id)target {
   if (self = [super init]) {
      _target = [target retain];
   }
   return self;
}

-(void)dealloc {
   [_target release];
   [super dealloc];
}

If the UIViewController has already been dismissed when the NSOperation gets around to running, then the call to release triggers it's dealloc on a background thread.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c