Reputation: 1425
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?
Upvotes: 0
Views: 107
Reputation: 7466
You also have the possibility to define the aInfo
variable as a class variable and release it in the following method:
– parser:didEndElement:namespaceURI:qualifiedName:
Upvotes: 1
Reputation: 69459
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;
}
Upvotes: 2
Reputation: 29767
[aInfo release];
or [aInfo autorelease];
at the end of the method
Upvotes: 6