0
我的同事和我遇到了一個問題,我們正在嘗試解決。它與內存分配有關。我們的代碼使用循環和componentsSeperateByString通過字符「\ n」拆分大文檔。奇怪的是,這永遠不會返回所有的內存。或者至少當我們檢查它時,是否有人可以查看下面的函數代碼,並告訴我們我們可能會做錯什麼。爲什麼ios componentsseperatebystring不能返回內存?
- (void)loadTagmeTest:(NSString *)selectedTargetName
{
NSString *path = [[NSBundle mainBundle] pathForResource:selectedTargetName ofType:@"tagme"];
NSString *objData = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *lines1;
NSArray *lineVertices1;
NSArray *lineNormals1;
NSArray *lineTexcoords1;
lines1 = [objData componentsSeparatedByString:@"\n"];
// Iterate through file once to discover how many vertices, normals, and faces there are
lines1 = [self getList:objData separator:@"\n"];
for (NSString * line in lines1)
{
if ([line hasPrefix:@"Verts: "])
{
lineVertices1 = [[line substringFromIndex:7] componentsSeparatedByString:@","];
}
else if ([line hasPrefix:@"Normals: "]){
lineNormals1 = [[line substringFromIndex:9] componentsSeparatedByString:@","];
}
else if ([line hasPrefix:@"TexCoords: "]){
lineTexcoords1 = [[line substringFromIndex:11] componentsSeparatedByString:@","];
}
}
}
編輯:這不再是當務之急,因爲我們推出我們自己的版本解析功能,所以現在的代碼使用較少的內存,實際上返回它使用它完成後的記憶,而且是速度稍快解析(整個文件(約10,000行)解析並轉換爲浮點數,放入數組等等,大約100ms。 (至少在我們上面的實現中)
謝謝。
你是怎麼測量的?你用ARC嗎? – borrrden
我正在使用vm_statistics_data和可用內存的數量進行測量,並使用泄漏/分配工具查看即使在函數結束時仍有多少內存被使用。 – Raigex
我的問題的第二部分呢?無論哪種方式,我注意到你仍然保持對3個實例數組的引用。 – borrrden