• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delayed -dealloc occurs on worker thread if object is "working". How?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delayed -dealloc occurs on worker thread if object is "working". How?


  • Subject: Re: Delayed -dealloc occurs on worker thread if object is "working". How?
  • From: BJ Homer <email@hidden>
  • Date: Wed, 2 Jun 2010 11:48:12 -0600

detachNewThreadSelector:target:withObject: retains both the target and the
object.

-BJ

On Wed, Jun 2, 2010 at 11:39 AM, Jerry Krinock <email@hidden> wrote:

> I allocate an object Foo on the main thread.  Then I spin off a secondary
> thread and give it a long task to do there, but immediately release the
> object, on the main thread.  I expect that the -release invoke -dealloc
> immediately, on the main thread.  To my amazement, the object is not
> deallocced until the task is finished, and to my further amazement, the
> dealloc method runs on the secondary thread.
>
> Someone please enlighten me.  This is Mac OS 10.6.3, Objective-C garbage
> collection = unsupported.
>
> Jerry Krinock
>
>
> #import <Cocoa/Cocoa.h>
>
> @interface Foo : NSObject {
> }
> @end
>
> @implementation Foo
>
> - (void)sleep5 {
>    NSLog(@"Sleeping for 5 on secondary thread") ;
>    sleep(5) ;
> }
>
>
> - (void)dealloc {
>    [super dealloc] ;
>    NSLog(@"Did dealloc a Foo") ;
> }
>
> @end
>
>
> int main(int argc, char *argv[]) {
>    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;
>
>    Foo* foo = [[Foo alloc] init] ;
>    [NSThread detachNewThreadSelector:@selector(sleep5)
>                             toTarget:foo
>                           withObject:nil] ;
>    [foo release] ;
>
>    sleep(10) ;
>
>    NSLog(@"Terminating") ;
>    [pool release] ;
>    return 0 ;
> }
>
> RESULT:
>
> 10:23:00.879 LittleTool[83071:1103] Sleeping for 5 on secondary thread
> 10:23:05.884 LittleTool[83071:1103] Will dealloc a Foo
> 10:23:05.885 LittleTool[83071:1103] Did dealloc a Foo
> 10:23:10.879 LittleTool[83071:80f] Terminating
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [SOLVED] Delayed -dealloc occurs on worker thread if object is "working".
      • From: Jerry Krinock <email@hidden>
References: 
 >Delayed -dealloc occurs on worker thread if object is "working". How? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Delayed -dealloc occurs on worker thread if object is "working". How?
  • Next by Date: Re: The Unadopted Protocol
  • Previous by thread: Delayed -dealloc occurs on worker thread if object is "working". How?
  • Next by thread: Re: [SOLVED] Delayed -dealloc occurs on worker thread if object is "working".
  • Index(es):
    • Date
    • Thread