I am honestly not able to figure out when to releas these objects, Please help
+ (DrawData*) load {
DrawData *newDrawData = [[DrawData alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL keepLoading = YES;
int curIndex = 0;
while ( keepLoading ) {
BoardData *tmpBoard = [[BoardData alloc] init];
NSString *imageFilename = [[NSString alloc] initWithFormat:@"iCanvas_image_%d.png", curIndex];
NSString *metadataFilename = [[NSString alloc] initWithFormat:@"iCanvas_metadata_%d.txt", curIndex];
NSString *layersFilename = [[NSString alloc] initWithFormat:@"iCanvas_layers_%d.dat", curIndex];
imageFilename = [documentsDirectory stringByAppendingPathComponent:imageFilename];
metadataFilename = [documentsDirectory stringByAppendingPathComponent:metadataFilename];
if ( [fm fileExistsAtPath:imageFilename] && [fm fileExistsAtPath:metadataFilename] ) {
NSString *metadataFile = [[NSString alloc] initWithContentsOfFile:metadataFilename];
NSArray *metadata = [metadataFile componentsSeparatedByCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
tmpBoard.drawImageTypeOverlay = [[metadata objectAtIndex:0] intValue];
tmpBoard.brushSize = [[metadata objectAtIndex:1] floatValue];
tmpBoard.brushColorRed = [[metadata objectAtIndex:2] floatValue];
tmpBoard.brushColorGreen = [[metadata objectAtIndex:3] floatValue];
tmpBoard.brushColorBlue = [[metadata objectAtIndex:4] floatValue];
tmpBoard.brushColorAlpha = [[metadata objectAtIndex:5] floatValue];
tmpBoard.isErasing = [[metadata objectAtIndex:6] intValue];
tmpBoard.eraseSize = [[metadata objectAtIndex:7] floatValue];
tmpBoard.isSelected = [[metadata objectAtIndex:8] intValue];
tmpBoard.layers = [NSMutableArray arrayWithContentsOfFile:layersFilename];
[newDrawData addBoard:tmpBoard];
}
else {
keepLoading = NO;
}
[tmpBoard release];
}
[pool release];
return newDrawData;
}