Instruments leaks says that this code leaks:
NSString *name = [file substringToIndex:i];
Layer *actualLayer = nil;
for (Layer *lay in layers) {
if ([lay.layerName isEqual:name]) {
actualLayer = lay;
}
}
name is the leaking object. There are some strange things: it only leaks sometimes, not always (this snippet of code is executed hundreds of time during a normal execution of my app, but it leaks just 3-4 times). The other strange thing is that i suppose the name object to be an autoreleasing object and it is never explicitaly retained or released, so how could it be that it's leaked?
Taking a look at the stack, substringWithRange is called by substringToIndex, so the problem I think it's in the substringToIndex method.