简体   繁体   English

在UIViewController之间切换时发生什么类型的内存问题?

[英]What type of memory issue is happening when switching between UIViewControllers?

I have a slideshow view controller where the memory usage is steady, and when you tap it, it switches to another view controller. 我有一个幻灯片显示视图控制器,内存使用率稳定,当您点击它时,它将切换到另一个视图控制器。 During the switch, the memory usage spikes, and stays steady. 在切换过程中,内存使用量会激增并保持稳定。 (Which I assume is normal) Then in 30 seconds, I have it timeout & go back to the slideshow view controller, and the memory usage is higher that what it originally was for the view controller. (我认为这是正常的)然后在30秒内使它超时并返回到幻灯片显示视图控制器,并且内存使用率比原来的视图控制器要高。 Both of the switches are using segues. 两个开关都使用segues。 When you tap the view & make it switch, the memory spikes again. 当您点击视图并使其切换时,内存再次达到峰值。 This time it spiked higher than what it spiked to last time. 这次,它的峰值高于上次的峰值。 This continues forever & ever. 这将永远持续下去。 Here is a picture: 这是一张图片:

在此处输入图片说明

This warning also keeps popping up in the console: 该警告还会在控制台中不断弹出:

Warning: Attempt to present on whose view is not in the window hierarchy! 警告:尝试显示不在窗口层次结构中的视图!

What type of memory problem is occurring, and what could be causing the increases in memory usage? 发生哪种类型的内存问题,什么原因可能导致内存使用量增加?

EDIT: 编辑:

Here is how i'm going back to the slideshow view controller: 这就是我要回到幻灯片显示视图控制器的方式:

timeOut = [NSTimer scheduledTimerWithTimeInterval:25 target:self selector:@selector(timeOutMethod) userInfo:nil repeats:NO];

-(void) timeOutMethod{

    [self performSelector:@selector(loadSlideshowView)
               withObject:nil
               afterDelay:5];

}

-(void) loadSlideshowView{


    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    SlideShowViewController *myVC = (SlideShowViewController *)[storyboard instantiateViewControllerWithIdentifier:@"slideShowImages"];
    [self presentViewController:myVC animated:YES completion:nil];

}

As the documentation for instantiateViewControllerWithIdentifier: says: 作为instantiateViewControllerWithIdentifier的文档,它说:

This method creates a new instance of the specified view controller each time you call it. 每次调用时,此方法都会创建指定视图控制器的新实例。

So every time you timeout, you are creating new copies of your view controller whilst the old ones remain in memory in the background. 因此,每次超时时,您都在创建视图控制器的新副本,而旧的则保留在后台的内存中。

As Konsy says, either try dismissViewController or an unwind segue . 正如Konsy所说,请尝试dismissViewController或unsegue segue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM