My co-worker and I are having a problem we are trying to fix. It has to do with memory allocation. Our code uses loops and componentsSeperateByString to split a large document by the character "\n". The weird thing is that this never returns all the memory it took. Or at least when we check it doesn't can someone look at the code below for the function and tell us what we might be doing wrong.
- (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:@","];
}
}
}
Edit: This is no longer a pressing matter as we rolled our own version of the parsing function, so now the code uses less memory, actually returns the memory it uses after it is done, and is slightly faster to parse (a whole document (about 10,000 lines) parses and is transormed into floats, put into arrays etc, etc in about 100ms.
Although it is not a pressing concern i would like to know why the memory allocation of NSString is so bad (at least in our implementation above).
Thanks.