Hi guys,
I am making a small application and at some part I am facing the memory leaks in some lines, here is the code I am submitting
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask,
YES
);
NSString * recordingDirectory = [filePaths objectAtIndex: 0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *recordingDirectoryPath = [NSString stringWithString:recordingDirectory];
NSString *cachePath = [recordingDirectoryPath stringByAppendingPathComponent"ayisearch.plist"];
if (![fileManager fileExistsAtPath:cachePath])
{
}
else{
//Get the Current Dictionaary
NSLog(@"%@",cachePath);
NSArray *testArray = [[NSArray alloc] initWithContentsOfFile:cachePath];
NSMutableArray *testArray1 = [[NSMutableArray alloc] initWithCapacity:0];
for(int i=0; i<[testArray count];i++)
{
getProfile = [[NSMutableDictionary alloc] initWithDictionary: [testArray objectAtIndex:i]];
NSString *profileName = [getProfile objectForKey"name"];
NSString *imagePath = [recordingDirectoryPath stringByAppendingPathComponentrofileName];
NSString *imageName = [NSString stringWithFormat"%@.jpg",profileName];
NSString *imageFilePath = [imagePath stringByAppendingPathComponent:imageName];
NSURL *imgurl = [NSURL URLWithString:[getProfile objectForKey"img"]];
NSLog(@"finalURL: %@",imgurl);
NSData *data = [[NSData alloc] initWithContentsOfURL:imgurl];
[fileManager createDirectoryAtPath:imagePath attributes:nil];
[data writeToFile:imageFilePath atomically:NO];
[getProfile setObject:imageFilePath forKey"img"];
[testArray1 addObject:getProfile];
[data release];
[getProfile release];
}
testArray = [NSArray arrayWithArray:testArray1];
[testArray1 release];
getProfile = [NSMutableDictionary dictionaryWithDictionary:[testArray objectAtIndex:0]];
NSMutableArray *updateTestArray = [NSMutableArray arrayWithArray:testArray];
[updateTestArray removeObjectAtIndex:0];
testArray = updateTestArray;
updateTestArray = nil;
[testArray writeToFile:cachePath atomically:NO];
NSUInteger *noOfProfiles = (NSUInteger *) [testArray count];
NSLog(@"no of records we are getting from the server are ");
if(noOfProfiles <= kCacheProfiles)
{
[NSThread detachNewThreadSelectorselector(doSearch) toTarget:self withObject:nil];
}
[testArray release];
}
The colored parts are sending leaks, please guide me here. Thanks in advance
I am making a small application and at some part I am facing the memory leaks in some lines, here is the code I am submitting
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask,
YES
);
NSString * recordingDirectory = [filePaths objectAtIndex: 0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *recordingDirectoryPath = [NSString stringWithString:recordingDirectory];
NSString *cachePath = [recordingDirectoryPath stringByAppendingPathComponent"ayisearch.plist"];
if (![fileManager fileExistsAtPath:cachePath])
{
}
else{
//Get the Current Dictionaary
NSLog(@"%@",cachePath);
NSArray *testArray = [[NSArray alloc] initWithContentsOfFile:cachePath];
NSMutableArray *testArray1 = [[NSMutableArray alloc] initWithCapacity:0];
for(int i=0; i<[testArray count];i++)
{
getProfile = [[NSMutableDictionary alloc] initWithDictionary: [testArray objectAtIndex:i]];
NSString *profileName = [getProfile objectForKey"name"];
NSString *imagePath = [recordingDirectoryPath stringByAppendingPathComponentrofileName];
NSString *imageName = [NSString stringWithFormat"%@.jpg",profileName];
NSString *imageFilePath = [imagePath stringByAppendingPathComponent:imageName];
NSURL *imgurl = [NSURL URLWithString:[getProfile objectForKey"img"]];
NSLog(@"finalURL: %@",imgurl);
NSData *data = [[NSData alloc] initWithContentsOfURL:imgurl];
[fileManager createDirectoryAtPath:imagePath attributes:nil];
[data writeToFile:imageFilePath atomically:NO];
[getProfile setObject:imageFilePath forKey"img"];
[testArray1 addObject:getProfile];
[data release];
[getProfile release];
}
testArray = [NSArray arrayWithArray:testArray1];
[testArray1 release];
getProfile = [NSMutableDictionary dictionaryWithDictionary:[testArray objectAtIndex:0]];
NSMutableArray *updateTestArray = [NSMutableArray arrayWithArray:testArray];
[updateTestArray removeObjectAtIndex:0];
testArray = updateTestArray;
updateTestArray = nil;
[testArray writeToFile:cachePath atomically:NO];
NSUInteger *noOfProfiles = (NSUInteger *) [testArray count];
NSLog(@"no of records we are getting from the server are ");
if(noOfProfiles <= kCacheProfiles)
{
[NSThread detachNewThreadSelectorselector(doSearch) toTarget:self withObject:nil];
}
[testArray release];
}
The colored parts are sending leaks, please guide me here. Thanks in advance