0

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. Both of the switches are using 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:

enter image description here

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];

}
DCAdams
  • 65
  • 1
  • 7
  • When your timeout occurs how are you going back to your previous controller - can you show us that code? It sounds like you are re-presenting new copies of views rather than unwinding to the original. – Ali Beadle Jul 14 '16 at 18:27
  • @AliBeadle I added it into my question. – DCAdams Jul 14 '16 at 18:32
  • 1
    try cutting down on the duration of the delay and see what happens. Also is the slideshow view controller a previous view controller to this one? if so you could just do the dismissViewController function instead of presenting the view controller again. – Konsy Jul 14 '16 at 18:42
  • @Konsy I tried lowering the delay, and there was no difference with memory usage. I also tried dismissing the view, and sadly that did not change anything either. – DCAdams Jul 14 '16 at 18:48
  • @DCAdams that's strange. It seems that it is reloading the VC causing higher memory to be used. Stupid question but have you tried to load the view through segues not programatically? – Konsy Jul 14 '16 at 18:50
  • @Konsy I don't think i've tired that yet – DCAdams Jul 14 '16 at 19:07
  • try that and if that does nothing then you're have to deal with it unfortunately :( sorry if i couldn't of been any help! – Konsy Jul 14 '16 at 19:08
  • @Konsy Thank you for the help though, Ali Beadle answered the question, it no longer keeps spiking each time. – DCAdams Jul 14 '16 at 19:22
  • glad to hear! Keep coding – Konsy Jul 14 '16 at 19:23

1 Answers1

1

As the documentation for instantiateViewControllerWithIdentifier: says:

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.

Community
  • 1
  • 1
Ali Beadle
  • 4,202
  • 3
  • 26
  • 53
  • Thank you! This seems to be working, it rises the first time, but stays there and it no longer keeps spiking each time. – DCAdams Jul 14 '16 at 19:20