2011-09-14 169 views
0

我已經在函數內部分配了對象[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]; 
     } 

    } 
} 

在這種情況下,如何管理內存問題?

+1

它不是真的很清楚你問這裏。 –

回答

6

[aInfo release];[aInfo autorelease];在方法

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; 
} 
1

你也必須定義aInfo變量作爲類變量並釋放它在以下方法的可能性:

– parser:didEndElement:namespaceURI:qualifiedName: