title: How to free memory when moving between SpriteKit scenes
body: <p>I made a spritekit game with 10 different scenes with a single base scene which directs to each of the scenes. when I move to and from every scene, memory keeps going up, assuming due to texture caching, as explained here before. </p>
  
  <p>The problem is that memory keeps going up to 300 MB and in weak devices it crashes after 3-4 scenes. I have tried to "free" memory using a cleanup function: </p>
  
  <pre class="lang-c prettyprint-override"><code>- (void)willMoveFromView:(SKView *)view {
  
      [self.children enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
          SKNode* child = obj;
          [child removeAllActions];
      }];
  
      [self removeAllChildren];       
  }
  </code></pre>
  
  <p>However, this doesn't help. Any ideas how to solve this?</p>
  
  <p>This is my main (and only) ViewController:</p>
  
  <pre class="lang-c prettyprint-override"><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      // Configure the view.
      SKView * skView = (SKView *)self.view;
  //    skView.showsFPS = YES;
      skView.showsNodeCount = YES;
  
      /* Sprite Kit applies additional optimizations to improve rendering performance */
      skView.ignoresSiblingOrder = YES;
  
      // Create and configure the scene.
      MainMenu *scene = [MainMenu sceneWithSize: self.view.bounds.size];
      scene.scaleMode = SKSceneScaleModeAspectFill;
  
      // Present the scene.
      [skView presentScene:scene];
  }
  </code></pre>
  
  <p>and my switch to scene code:</p>
  
  <pre class="lang-c prettyprint-override"><code>- (void)switchToRoom
  {
      SKTransition *transition = [SKTransition fadeWithColor:[UIColor whiteColor] duration:0.5];
  
      SKScene * scene = [[RoomScene alloc] initWithSize:self.size];
  
      [self.view presentScene:scene transition:transition];
  
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After 3 days of struggling I found out that my bad practice was using a "curtain" styled animation to navigate between scenes. The problem with this method is that a "curtain" is at the size of the screen, and an Atlas of curtains with ~30 textures is HUGE, and probably what caused the memory to run so high, I am not sure why it caused a leak alike behavior, but when reducing the number of frames inside the atlas to around 10, I no longer see memory goes that high, and it looks like that there is no leak. </p>
  
  <p>Another bad practice for this situation was to use "preloadTextures:textures" method, which appears to consume a lot of memory for this type of animation. When I removed it, performance became even better. </p>