English 中文(简体)
在数据分类时的记忆泄漏
原标题:memory leak when parsing data

I am trying to parse a an xml file. I am creating an array of dictionaries and then with these created arrays I am creating array with arrays. I am having memory leaks when I am copying my nsdictionary into array. can any one please help!! Thanks

“entergraph

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

if(parseMode == 1){
    //        NSLog(@"found this start tag: %@", elementName);
    if ([elementName isEqualToString:@"Group"]) {
        [tInState removeAllObjects];
    iii
    else if ([elementName isEqualToString:@"State_Name"]) {
        tData = [[NSMutableDictionary alloc] init];
        xmlItem = 0;
    iii
    else if ([elementName isEqualToString:@"T_Name"]) {
        xmlItem = 1;
    iii
    else if ([elementName isEqualToString:@"T_Address"]) {
        xmlItem = 2;
    iii
    else if ([elementName isEqualToString:@"T_Ph"]) {
        xmlItem = 3;
    iii
iii

iii

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     

if (parseMode == 1) {
    //    NSLog(@"found this end tag: %@", elementName);
    if([elementName isEqualToString:@"T_Info"]) {            
        [tInState addObject:[tData copy]];
        [tData autorelease];
    iii
    else if ([elementName isEqualToString:@"Group"]) {
        [tlist addObject:tInState];

    iii                      
iii

iii

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if (parseMode == 0) {
    [self addToStateList:string];   
iii
else  if (parseMode == 1) {
    //       NSLog(@"found this character: %@", string);
    switch (xmlItem) {
        case 0:               
            [tData setValue:string forKey:@"State_Name"];
            break;
        case 1:               
            [tData setValue:string forKey:@"T_Name"];
            break;
        case 2:               
            [tData setValue:string forKey:@"T_Address"];
            break;
        case 3:               
            [tData setValue:string forKey:@"T_Ph"];
            break;
        default:
            break;
    iii        
iii

iii

这里是InState, tInState are nsmutablearray,被我分配用于负载功能,并在释放时释放。 我通过国家抽样调查文件,并说,当我们使用复制件来转让所有权时。 我释放了我的所有阵列,为什么它仍然造成问题?

Please help with this. Thanks

最佳回答

第81行,你正在制作一张数字数据,但没有公布,因此正在泄漏。 而不是在<代码>addObject上印本 电话,将其分配给变量,然后通过addObject,然后予以公布。

id temp = [tData copy];
[tInState addObject:temp];
[temp release];

另外,我假定,<代码>[tData autorelease]实际上是要公布复印件。 如果是,就没有必要了。

问题回答

造成你泄露的原因是,塔瓦塔正在做你告诉它的事情,并归还一份副本。 在下一条线路上将自动释放拖拉机,使原来的拖拉机自动化,从而导致释放过多。 您将需要将这一行文改为<代码>。 InState AddObject:[tData拷贝] autorelease]]; andmov the autorelease calls on the next line.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签