Question

How can i force a autoreleasepool to release my autorelease object which was created outside the autoreleasepool {}

the code im using

- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection {

    NSError *error = nil;
    id response = [NSJSONSerialization JSONObjectWithData:responseData options:nil error:&error];
    [responseData release];
    if (error) {
            NSLog(@"ERROR JSON PARSING : %@", error.localizedDescription);
    }

    [delegate databaseUpdates:response connection:self];
}

- (void)databaseUpdates:(id)_updates connection:(URLConnection *)_urlConnection {
    if (_updates) {

        NSDictionary *updates = nil;
        @autoreleasepool {

            updates = [[_updates valueForKey:@"objects"] retain];

            //Release _updates here!?!
        }
    }
}

Thanks a lot

Était-ce utile?

La solution

Simply call autorelease while in the scope of the autorelease pool, that will automatically add the object to the pool. Though, it looks like you are trying to solve the wrong problem here. If you really mean _updates, then that shouldn't be memory management by the method but by the caller (and it already is! JSONObjectWithData:options:error: already returns an autoreleased instance), and if you mean updates, well, simply don't retain it.

Autres conseils

It is not possible. I think you need this

- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection {
    @autoreleasepool {
        NSError *error = nil;
        id response = [NSJSONSerialization JSONObjectWithData:responseData options:nil error:&error];
        [responseData release];
        if (error) {
                NSLog(@"ERROR JSON PARSING : %@", error.localizedDescription);
        }

        [delegate databaseUpdates:response connection:self];
    } // response will be released here
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top