NSDICTIONARY获取内容的CRASH

NSString *path = [self.dataPath stringByAppendingPathComponent:@"dummy.plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString *dummyKeyValue = [dict valueForKey:@"dummyKey"];

// NSLog(@"%@",[NSString stringWithString:dummyKeyValue]);

[dict release];http://www.zyxsw.net

NSString *anotherString = [dummyKeyValue lowercaseString];
当使用到dummyKeyValue时 挂掉。

背景:

  NSDictionary在获得里面的值后, 对Dict进行释放。此时value也全部释放了。 当有引用在使用该value时,就会野指针。

 

解决办法:

NSString *dummyKeyValue = [[[dict valueForKey:@"dummyKey"] retain] autorelease];
posted @ 2014-11-27 23:19  天师符  阅读(324)  评论(0编辑  收藏  举报