我在函数[Method。]
中分配了对象解析器内部方法。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict{
Information *aInfo = [[Information alloc] init];
if([elementName isEqualToString:@"data"]){
aInfo.strStoreId = [attributeDict valueForKey:@"storeid"];
[arrayList addObject:aInfo];
} else if ([ActionType isEqualToString:@"action"]) {
if([elementName isEqualToString:@"data"]) {
aInfo.strStoreId = [attributeDict valueForKey:@"storeid"];
[arrayList addObject:aInfo];
}
}
}
在这种情况下如何管理内存问题?
答案 0 :(得分:6)
[aInfo release];
或[aInfo autorelease];
答案 1 :(得分:2)
您可以释放该对象,将其添加到数组中增加了保留计数。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict{
Information *aInfo = [[Information alloc] init];
if([elementName isEqualToString:@"data"]){
aInfo.strStoreId = [attributeDict valueForKey:@"storeid"];
[arrayList addObject:aInfo];
} else if ([ActionType isEqualToString:@"action"]) {
if([elementName isEqualToString:@"data"]) {
aInfo.strStoreId = [attributeDict valueForKey:@"storeid"];
[arrayList addObject:aInfo];
}
}
[aInfo release], aInfo = nil;
}
答案 2 :(得分:1)
您还可以将aInfo
变量定义为类变量,并使用以下方法释放它:
– parser:didEndElement:namespaceURI:qualifiedName: