user891268
user891268

Reputation: 1425

Memory management issue

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

Answers (3)

Infinite Possibilities
Infinite Possibilities

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

rckoenes
rckoenes

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

beryllium
beryllium

Reputation: 29767

[aInfo release]; or [aInfo autorelease]; at the end of the method

Upvotes: 6

Related Questions