首页 > 代码库 > NSDICTIONARY获取内容的CRASH

NSDICTIONARY获取内容的CRASH

NSString *path = [self.dataPath stringByAppendingPathComponent:@"dummy.plist"];NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];NSString *dummyKeyValue = http://www.mamicode.com/[dict valueForKey:@"dummyKey"];// NSLog(@"%@",[NSString stringWithString:dummyKeyValue]);[dict release];http://www.zyxsw.netNSString *anotherString = [dummyKeyValue lowercaseString];
当使用到dummyKeyValue时 挂掉。

背景:

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

 

解决办法:

NSString *dummyKeyValue = http://www.mamicode.com/[[[dict valueForKey:@"dummyKey"] retain] autorelease];

NSDICTIONARY获取内容的CRASH