同僚と私は解決しようとしている問題を抱えています。それはメモリ割り当てに関係しています。このコードでは、ループと componentsSeperateByString を使用して、大きなドキュメントを文字 "\n" で分割しています。奇妙なことは、これが使用したすべてのメモリを決して返さないことです。または、少なくとも私たちがチェックしたとき、誰かが関数の以下のコードを見て、私たちが間違っている可能性があることを教えてくれません.
- (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 行) を解析し、約 100 ミリ秒で float に変換したり、配列などに入れたりします。
差し迫った懸念事項ではありませんが、なぜ NSString のメモリ割り当てがそれほど悪いのか知りたいです (少なくとも上記の実装では)。
ありがとう。