【发布时间】:2013-08-26 23:12:44
【问题描述】:
我有一个方法用于从 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) 失败(错误代码=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试 PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试 PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试 PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试 PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试 2013-08-26 19:01:15.644 PIslandTerrainGenerator[29202:a0b] beach.upper_elevation_threshold PSIslandTerrainGenerator(29202,0x1eb3a28) malloc: *** mmap(size=2097152) failed (error code=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) failed (error code=12)
* 错误:无法分配区域 * 在 malloc_error_break 中设置断点进行调试
我进入 Instruments 并分析了该应用程序,结果表明,每当它崩溃时,该应用程序都会使用超过 3 GB 的内存。所以我猜测这个方法中的某些东西每次运行时都无法释放,但无法准确定位。
【问题讨论】:
-
您是否“在 malloc_error_break 中设置断点进行调试”?
-
@CarlNorum - 我不确定“malloc_error_break”的确切位置,所以我没有设置断点。
标签: objective-c xcode debugging runtime-error out-of-memory