我有一种方法用于从 plist 中检索数据,如下所示:
方法本身是这样的:
//'path' is of the form "beach.color.green" (for example)
-(NSString *)elementWithPath: (NSString *)path {
//'self.target' is the path to the plist
NSDictionary *currentData = [NSDictionary dictionaryWithContentsOfFile:self.target];
//This is the number of nested layers that the desired data lies in.
NSUInteger numberOfLayers = [[path componentsSeparatedByString:@"."] count];
for(NSUInteger i = 0; i < numberOfLayers; i++) {
NSString *pathComponentInCurrentLayer = [path componentsSeparatedByString:@"."][i];
//If the data we're currently searching through is a dictionary...
if([[currentData objectForKey:pathComponentInCurrentLayer] isKindOfClass:[NSDictionary class]])
//Narrow our search by making that dictionary the dictionary to search through
currentData = [currentData objectForKey:pathComponentInCurrentLayer];
//It's not a dictionary, so it has to be the desired data...
else
//So we return it
return [currentData objectForKey:pathComponentInCurrentLayer];
}
return nil;
}
我知道该方法工作正常,因为我通过断点逐步执行它并验证它返回了正确的输出。问题是,每次我运行我的项目(其中多次调用此方法)时,都会出现以下错误:
PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以调试 PIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以调试 PIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以调试 PIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以调试 PIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点进行调试 2013-08-26 19:01:15.644 PSIslandTerrainGenerator[29202:a0b] beach.upper_elevation_threshold PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size= 2097152) 失败(错误代码=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以进行调试 2013-08-26 19:01:15.647 PSIslandTerrainGenerator[29202:a0b] low_grass.upper_elevation_threshold PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size= 2097152) 失败(错误代码=12)
* 错误:无法分配区域 *在 malloc_error_break 中设置断点以进行调试
我进入 Instruments 并分析了该应用程序,它显示每当它崩溃时,该应用程序都会使用超过 3 GB 的内存。所以我猜测这个方法中的某些东西每次运行时都无法释放,但无法准确指出是什么。