我已经通过 Edit-Refactor->Convert to ARC 将一个非 ARC 项目更改为 ARC,除了以这种方式调用的函数之外,所有泄漏现在都已消失:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(DownloadAll)
object:nil];
operation.queuePriority=NSOperationQueuePriorityVeryHigh;
[queue addOperation:operation];
这是功能:
-(void)DownloadAll{
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath;
bool fileExists;
NSString * strSelect = [NSString stringWithFormat:@"SELECT NoOfAyas from tbSura"];
NSMutableArray * marrItems = [gObj.sqlObj selStatement:strSelect :1];
for (int i =1; i<=114; i++) {
documentsPath = [NSString stringWithFormat:@"%@/%@/%i",[paths objectAtIndex:0],DefaultReader,i];
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:documentsPath];
if (!fileExists)
[[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:nil];
for (int j =1; j<=[[marrItems objectAtIndex:i-1] intValue]; j++) {
int indx=[ReadersIDs indexOfObject:DefaultReader];
NSString *str=[NSString stringWithFormat:@"%@%i/%i.mp3",[ReadersPaths objectAtIndex:indx],i,j];
documentsPath = [NSString stringWithFormat:@"%@/%@/%i/%@",[paths objectAtIndex:0],DefaultReader,i,[str lastPathComponent]];
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:documentsPath];
if (!fileExists) {
@autoreleasepool {
NSError *err;
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:str] options:0 error:nil];
if (err) {
NSLog(@"%@",err);
}
if(!data)
NSLog(@"Aya : %i %i",i,j);
else
[data writeToFile:documentsPath atomically:YES];
}
}
}
}
}
内存随着时间的推移而上升和上升,下载对象并在收到内存警告后崩溃
感谢您提前提供帮助。