在我的 iOS 应用程序中,当我从 viewController A 到 B 时,它使用系统内存是可以的。
但问题是,当我从 viewController A 到 B 再回到 A 再到 B 时,这会不断堆积越来越多的内存。
为什么它在返回视图 A 时不释放所有使用的内存。
我正在使用自动释放池。我正在消除不再需要的变量。
注意:我在视图 B 中使用 GCD,但我也在释放 GCD 中的内存。
我不知道为什么会这样。或者当我在视图 A 中时,有没有办法完全卸载视图 B 使用的所有资源?
更新:
我没有从 B 回到 A。我只是使用后退按钮。
这是我从视图 A 的转场
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
@autoreleasepool {
PhotosCollectionViewController *photoCollection=[segue destinationViewController];
NSIndexPath *path=[self.tableView indexPathForSelectedRow];
// get the cell tag for the selected row
NSIndexPath *path1=[NSIndexPath indexPathForRow:[path row] inSection:0];
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:path1];
[photoCollection setPassedID:[[elements objectAtIndex:path1.row] objectAtIndex:0]];
// set the title of the next view controller
[photoCollection setTitle:cell.textLabel.text];
photoCollection=nil;
path=nil;
path1=nil;
}
}
编辑
我在 viewDidLoad 中的视图 b 中使用的长时间运行的进程
photoQueue=dispatch_queue_create("com.prepare.photos", nil);
dispatch_async(photoQueue, ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(goToBackground)
name:UIApplicationWillResignActiveNotification object:nil];
display_photos=[[NSMutableArray alloc] init];
// iterate through photos array and create MWPhoto object out of it
// init ns cache
//myCache=[[NSCache alloc] init];
int j=0;
for(j=0;j<[photos count];j++){
//NSLog(@"filename %@",[[photos objectAtIndex:i] objectAtIndex:0]);
MWPhoto *mw=[MWPhoto photoWithFilePath:[self.documentsDirectory stringByAppendingPathComponent:[[photos objectAtIndex:j] objectAtIndex:0]]];
[display_photos addObject:mw];
mw=nil;
}
//dispatch_release(photoQueue);
});