I created a delete file method, calls it through NSThread. Through Activity Monitor examined that the actual memory takes 100M,but why this thread after completion has not released any memory to take the memory not to reduce actually?
code:
-(void)removeFilesThread:(NSDictionary *)parameter
{
@autoreleasepool
{
NSString *filePath=[parameter objectForKey:@"FilePath"];
NSString *fileType=[parameter objectForKey:@"FileType"];
NSUInteger fileSaveDays=[[parameter objectForKey:@"FileSaveDays"] unsignedIntegerValue];
NSUInteger fileSaveCount=[[parameter objectForKey:@"FileSaveCount"] unsignedIntegerValue];
NSFileManager *fileManage=[NSFileManager defaultManager];
NSArray *filesName=[fileManage contentsOfDirectoryAtPath:filePath error:nil];
NSMutableDictionary *sortFileTypeDic=[[NSMutableDictionary alloc] init];
for (NSString *fileName in filesName)
{
NSString *pathExtension=[fileName pathExtension];
NSArray*fileTypes=[fileType componentsSeparatedByString:@"|"];
if ([fileTypes containsObject:@"all"]||[fileTypes containsObject:pathExtension])
{
NSString *fileFullPath=[filePath stringByAppendingPathComponent:fileName];
NSDictionary *fileAttributes=[fileManage attributesOfItemAtPath:fileFullPath error:nil];
NSDate *fileModifDate=[fileAttributes objectForKey:NSFileModificationDate];
if (fileModifDate)
{
NSMutableDictionary *filesModifDateDic=([LLKStatic estimateIdClass:[NSDictionary class] idValue:[sortFileTypeDic objectForKey:pathExtension]])?[[NSMutableDictionary alloc]initWithDictionary:[sortFileTypeDic objectForKey:pathExtension]]:[[NSMutableDictionary alloc] init];
[filesModifDateDic setObject:fileModifDate forKey:fileFullPath];
[sortFileTypeDic setObject:filesModifDateDic forKey:pathExtension];
}
}
}
for (NSString *fileType in sortFileTypeDic)
{
NSMutableDictionary *filesModifDateDic=[LLKStatic estimateIdClass:[NSDictionary class] idValue:[sortFileTypeDic objectForKey:fileType]];
NSArray *filesBySortValue=[filesModifDateDic keysSortedByValueUsingSelector:@selector(compare:)];
if (filesBySortValue.count>fileSaveCount)
{
NSArray *removeSaveFiles=[filesBySortValue subarrayWithRange:NSMakeRange(0, filesBySortValue.count-fileSaveCount)];
for (NSString *fileFullPath in removeSaveFiles)
{
NSDate *modifiDate=[LLKStatic estimateIdClass:[NSDate class] idValue:[filesModifDateDic objectForKey:fileFullPath]];
if (modifiDate)
{
NSDate *nowDate=[NSDate date];
NSInteger distanceDays=(NSInteger)[nowDate timeIntervalSinceDate:modifiDate]/86400;
if (distanceDays>=fileSaveDays)
{
[fileManage removeItemAtPath:fileFullPath error:nil];
}
}
}
}
}
}
}