2

i searched for a few hours but i can´t find what i´m actually searching for..

i want to free up my memory when im switching from a gameScene to my menuScene. as i read, it is possible if i add a viewController for each Scene and perfom Segues instead of transitions. but i want to keep it simple and use just one viewController. in addition to the first solution, it is possible to use UIImage´s instead of SKtexture. UIImage`s frees up their memory automatically by transition so i tried, and tried and i ended up here: (obviously not working)

//Load Animations
barrierUfoAtlas = [SKTextureAtlas atlasNamed:@"BarrierUfoAnimation"];
[barrierUfoAtlas preloadWithCompletionHandler:^{

    NSArray *barrierUfoAtlasNames = [barrierUfoAtlas textureNames];
    NSArray *sortetBarrierUfoAtlasNames = [barrierUfoAtlasNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    NSMutableArray *barrierUfoTextures = [NSMutableArray array];

    for (NSString *filename in sortetBarrierUfoAtlasNames) {

        NSData *imageData = [NSKeyedArchiver archivedDataWithRootObject:[barrierUfoAtlas textureNamed:filename]];

        UIImage *image = [UIImage imageWithData:imageData];

        SKTexture *texture = [SKTexture textureWithImage:image];

        [barrierUfoTextures addObject:texture];
    }
    self.barrierUfoAnimation = [SKAction animateWithTextures:barrierUfoTextures timePerFrame:0.0389];}];

can somebody help?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
NeoGER89
  • 412
  • 4
  • 16
  • 1
    when you present a new scene, the existing scene is deallocated if you haven't retained it somewhere in your code. http://stackoverflow.com/questions/19251337/ios-7-sprite-kit-freeing-up-memory – rakeshbs Feb 20 '15 at 07:49
  • Yeah, you seem to be going in directions you don't want to go (using UIImage, using a view controller per scene) because they don't really solve your problem. A view controller handles a view, a SKView to be precise, so that concept doesn't even make sense. And SK also releases memory intelligently, but it also caches resources intelligently because loading resources takes time. The question here is really: why do you need to release memory? Do you get a memory warning? Have you used Instruments to determine where the excess memory usage comes from? – CodeSmile Feb 20 '15 at 08:33
  • i know exactly where it comes from. i have a menuScene where you can choose between 5 "balls" and every ball has 3 animationAtlases (powerUpAnimations). in gameScene (didMoveToView) it loads this 3 Atlases. but when i´m gameOver and change now in my menuScene to another ball, it loads it´s animations too. it work´s until i played with 3 balls and then when i choose the foutrh, i get a memoryWarning. thats why i want to release memory. is there a way to set the gameScene to weak, so it releases memory automatically? – NeoGER89 Feb 20 '15 at 15:27
  • I am with @LearnCocos2D in that SK handles memory intelligently and that it is likely something in your code that is causing the animations to stay in memory. Perhaps how you are using those atlases? I would also be concerned at how soon you are getting this warning it doesn't really sound like you are doing much before you get to that point. The other thing I would check is if your memory drops when you get that message or does it get to the point of crashing. – Skyler Lauren Feb 20 '15 at 21:56
  • it was my code.. i´m way to long on this project i guess.. i´ve tried to set the whole scene to weak instead of the TextureAtlases. – NeoGER89 Feb 21 '15 at 05:45

0 Answers0