我有一個示例應用程序,看起來像社交網絡iOS應用程序。我是可可框架的新手,所以我正在研究示例代碼。在進行分析時,應用程序中有255個報告的內存泄漏。我能夠解決大約100個非常簡單的泄漏問題,但是我無法解決其餘問題。複製對象時目標內存泄漏
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//DLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if([MethodName isEqualToString:@"SignInStep"])
{
if ([elementName isEqualToString:@"item"])
{ // clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentUserId = [[NSMutableString alloc] init];
currentError = [[NSMutableString alloc] init];
}
}
}
的該項目的變量分配:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//DLog(@"ended element: %@", elementName);
if([MethodName isEqualToString:@"SignInStep"])
{
if ([elementName isEqualToString:@"item"])
{ // save values to an item, then store that item into the array...
[item setObject:currentUserId forKey:@"userId"];
[item setObject:currentError forKey:@"error"];
[SignIn addObject:[item copy]]; //Method returns Objective C Object with +1 retain count
}
}
}//Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
我收到以下錯誤:
1)方法返回目標C與對象+1保留計數
2 )對象泄漏:分配的對象未在此執行路徑中引用,並且保留計數爲+1
我在上面的代碼中提到了我剛剛收到這些泄漏的地方。誰能告訴我這是什麼原因?
感謝@parag Bafna。它的工作,但我真的不明白我們的代碼..你可以請詳細說明代碼 – Srini
當你添加一個對象到數組時,它會調用該對象的保留。 –