Why is there no offline pool when I execute the SelectorInBackground: function?

I call the method that goes in the background thread:

[self performSelectorInBackground:@selector(loadViewControllerWithIndex:) withObject:[NSNumber numberWithInt:viewControllerIndex]];

then I have this method implementation that is called by the selector:

- (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj {
    NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
    NSInteger vcIndex = [indexNumberObj intValue];

    Class c;
    UIViewController *controller = [viewControllers objectAtIndex:vcIndex];

    switch (vcIndex) {
        case 0:
            c = [MyFirstViewController class];
            break;
        case 1:
            c = [MySecondViewController class];
            break;
        default:
            NSLog(@"unknown index for loading view controller: %d", vcIndex); // error
            break;
    }

    if ((NSNull *)controller == [NSNull null]) {
        controller = [[c alloc] initWithNib];
        [viewControllers replaceObjectAtIndex:vcIndex withObject:controller];
        [controller release];
    }

    if (controller.view.superview == nil) {
        UIView *placeholderView = [viewControllerPlaceholderViews objectAtIndex:vcIndex];
        [placeholderView addSubview:controller.view];
    }

    [arPool release];
}

Althoug I create an autorelease pool for this thread, I always get this error:

2009-05-30 12:03:09.910 Demo[1827:3f03] *** _NSAutoreleaseNoPool(): Object 0x523e50 of class NSCFNumber autoreleased with no pool in place - just leaking
Stack: (0x95c83f0f 0x95b90442 0x28d3 0x2d42 0x95b96e0d 0x95b969b4 0x93a00155 0x93a00012)

If I pick up the auto resource pool, I get a whole bunch of messages like these. I also tried to create an autostart pool around the call to the performSelectorInBackground: function, but this does not help.

I suspect a parameter, but I do not know why the compiler complains about NSCFNumber. Did I miss something?

My instance variables are all "non-atomic." Could this be a problem?

UPDATE: , - โ€‹โ€‹ (, ivar), ? , ? ( , ;))

+5
2

, , (NSNumber) - , . , ( )

, , , (performSelectorInbackground) - , , .

.

+6

, , , , (NSNumber) - , . , ( )

NSAutoreleasePool :

- (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj {
    NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
    [indexNumberObj retain];

    ....

    [arPool release];
  }
+2

All Articles