I have allocated object inside the function [Method.]
inside parser 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];
}
}
}
How do I manage the memory issue in this case?
[aInfo release];
or [aInfo autorelease];
at the end of the method
You can just release the object, adding it to the array increased the retain count.
- (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;
}
您还可以将aInfo
变量定义为类变量,并通过以下方法释放它:
– parser:didEndElement:namespaceURI:qualifiedName:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.