Incorrect decrement of reference counting of an object that is not currently owned by the caller

Incorrect decrement of reference counting of an object that is not currently owned by the caller on the iPhone. This happens with NSString, which I clearly initialize and release in a for loop. I tried to do the same as the autoreleases line, but I get leaks. I guess the culprit is calling stringbytrimming. Any suggestions, by the way, this does not flow, but I get a warning in the assembly and analysis. Everything works fine and the application does not crash.

for(int i=0;i<storyQuantity;i++) {
            NSString *imageString = [[NSString alloc] init];
            imageString = [[[storiesArray objectAtIndex:i] objectForKey: @"image"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  // must add trimming to remove characters

            imageLoader *imageOperation = [[imageLoader alloc] initWithImageURL:imageString target:self action:@selector(didImageLoad:) number:i];

            AppDelegate_iPad *appDelegate = [[UIApplication sharedApplication] delegate];
            [appDelegate.queue_ addOperation:imageOperation];
            [imageOperation release];
            [imageString release];
        }

UPDATE - added my imageLoader class, which, as far as I know, has no leak

- (id)initWithImageURL:(NSString *)url target:(id)target action:(SEL)action number:(int)number {
    if(self = [super init]) {
        _action = action;
        _target = target;
        _number = number;
        if(url == nil) {
            return nil;
        } else {
            _imgURL = [[NSURL alloc] initWithString:[url copy]];
        }
    }
    return self;
}

- (id)main {

    NSAutoreleasePool *pool = [NSAutoreleasePool new];

    if ([self isCancelled]) {
        NSLog(@"OPERATION CANCELLED");
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [pool drain];
        return nil;
    } else {

        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

        NSData *imgData = [[NSData alloc] initWithContentsOfURL:_imgURL];
        UIImage *image = [[UIImage alloc] initWithData:imgData];
        [imgData release];

        if ([self isCancelled]) {
            NSLog(@"OPERATION CANCELLED");
            [image release];
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            [pool drain];
            return nil;
        } else { 

            NSNumber *tempNumber = [NSNumber numberWithInt:_number];
            NSDictionary *tempDict = [NSDictionary dictionaryWithObjectsAndKeys:tempNumber, @"number", image, @"image", nil];
            [image release];

            if([_target respondsToSelector:_action])
                [_target performSelectorOnMainThread:_action withObject:tempDict waitUntilDone:NO];
        }
    }

    [pool drain];
    return nil;

}

- (void)dealloc {
    [_imgURL release];
    [super dealloc];
}
+3
source share
2 answers

imageString, . ?

NSString *imageString = [[[storiesArray objectAtIndex:i] objectForKey: @"image"]
   stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

[imageString release], .

+5

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

, .

+1

All Articles