我试图从我的项目中消除记忆泄露,但现在有2个局势中的一米 st。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if (currentElement) {
[currentElement release];
currentElement = nil;
}
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init]; //leak #1
// DOING OTHER STUFF....
//......................
}
}
/*****************************************************************************/
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]){
[item setObject:currentTitle forKey:@"title"]; // leak #2
[item setObject:currentLink forKey:@"link"]; //leak #3
[bucket addObject:[item copy]]; // NSMutableArray *bucket
}
}
关于泄漏第1号,我试图在分配记忆之前就释放该项目,但如果是失事的话。 (我指的是,在<代码>项目 = [[SMutableDictionary alloc] init];。 i 使用
if (item){
[item release];
item=nil;
}
在我的处理方式中,即还有<代码>[项目发布];。
For leaks #2 and #3 i have no idea what s happening. Note: The 2 methods are called by an xml parser while parsing an XML file, every time an element is read.That is, NSMutableDictionary * item is re-used for every element.
任何建议? 事先感谢你: