Hello All,
I need to read the image from document folder and prepare UIImage out of that. but when I call this function everytime memory get increasing and for large scale image this scale is large. following is same code
-(UIImage*) GetSavedImageWithName:(NSString*) aFileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableString* str = [[NSMutableString alloc] initWithCapacity:300];
[str appendString:documentsDirectory];
[str appendString:@"/"];
[str appendString:aFileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL success = [fileManager fileExistsAtPath:str];
NSData *dataToWrite = nil;
UIImage* image = nil;
if(!success)
{
}
else
{
dataToWrite = [[NSData alloc] initWithContentsOfFile:str];
image = [UIImage imageWithData:dataToWrite]; YES;
}
if(dataToWrite)
{
[dataToWrite release];
dataToWrite = nil;
}
if(str)
{
[str release];
str = nil;
}
if(fileManager)
{
[fileManager release];
fileManager = nil;
}
return image;
}
Calling this way
[self SetFrontViewImage:[self GetSavedImageWithName:@"Edited"]];
I am not able to find where it is getting leak.
Thanks,
Sagar