1

ネットからデータを取得しているときにLibXmlパーサーでリークが発生しました。

以下のコードでは、リストを割り当てました

- (void)getCustomersList
{
// make an operation so we can push it into the queue
SEL method = @selector(parseForData);
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self  selector:method object:nil];
customersTempList = [[NSMutableArray alloc] initWithCapacity:20];// allocated list

[self.retrieverQueue addOperation:op];
[op release];
}

// return each recode 
// in parser .m class one of the condition in endElement where it shows a leak.

else if(0 == strncmp((const char *)localname, kCustomerElement, kCustomerElementLength)) 
{
    [customersTempList addObject:customer];
    printf("\n no of objects in temp list:%d", [customersTempList count]);
    if ([customersTempList count] == 20)
    {
        NSMutableArray* argsList = [customersTempList copy];//////////////////////here it is showing leak.
        printf("\n Calling reload data with %d new objects", [argsList count]);
        SEL selector = @selector(parser:addCustomerObject:);
        NSMethodSignature *sig = [(id)self.delegate methodSignatureForSelector:selector];
        if(nil != sig && [self.delegate respondsToSelector:selector]) {
            NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
            [invocation retainArguments];
            [invocation setTarget:self.delegate];
            [invocation setSelector:selector];
            [invocation setArgument:&self atIndex:2];
            [invocation setArgument:&argsList atIndex:3];
            [invocation performSelectorOnMainThread:@selector(invoke) withObject:NULL waitUntilDone:NO];

        }
        [customersTempList removeAllObjects];
    }
}

// returned the list after all the records are stored in the list
else if(0 == strncmp((const char *)localname, kCustomersElement, kCustomersElementLength)) {
                printf("\n Calling reload data with %d new objects", [customersTempList count]);
            NSMutableArray* argsList = [customersTempList copy];
    printf("\n Calling reload data with %d new objects", [argsList count]);

    SEL selector = @selector(parser:addCustomerObject:);
    NSMethodSignature *sig = [(id)self.delegate methodSignatureForSelector:selector];
    if(nil != sig && [self.delegate respondsToSelector:selector]) {
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
        [invocation retainArguments];
        [invocation setTarget:self.delegate];
        [invocation setSelector:selector];
        [invocation setArgument:&self atIndex:2];
        [invocation setArgument:&argsList atIndex:3];
        [invocation performSelectorOnMainThread:@selector(invoke) withObject:NULL waitUntilDone:NO];
    }
    [customersTempList removeAllObjects];

}
}

これから私を助けてください、ありがとう、マダン。

4

1 に答える 1

1

ええと、あなたはargsListそれを(経由してcopy)作成し、決してreleaseそれを作成しないので、あなたは漏れています。

それを使用する唯一のことは、それをの引数として設定することであり、その引数を保持するようにinvocation指示したので、ブロックの最後に置くか、最初に設定するinvocationことが簡単にできます。[argsList release]autorelease

(すでに存在するかどうかを確認せずに作成するためcustomersTempList、リークのリスクもあるようです。何度も呼び出すとリークします。)getCustomersList

于 2010-06-14T09:22:29.120 に答える