How to dealloc when changing scenes?

How to dealloc when changing scenes?
0.0 0


Hello, super noob here. I have a question with dealloction when changing scenes. My game is working fine except when changing scenes. For example, I have a “Restart” button that is supposed to reload the scene.

Do I need to do anything special when transitioning scenes as far as destructing goes?

Also, sort of related, is there any way to trace where the “Fatal Signal 11” comes from? If someone could point me to a tool that can help that’d be great. Thanks.


You don’t have to do anything special with deallocating, unless:

  1. You call retain(), then you must call release() later (usually inside your class destructor).
  2. You’ve already used too much memory for your textures. You’d better clear the texture cache every time you’re replacing scene. I always do this inside class destructor:
    auto cacher = CCSpriteFrameCache::sharedSpriteFrameCache();


How do you replace your scene anyway? This is what I do if I’m replacing scene:


Signal 11, or officially know as “segmentation fault”, means that the program accessed a memory location that was not assigned. That’s usually a bug in the program. So if you’re writing your own program, that’s the most likely cause.

I assume that you’re developing for Android, LogCat should be enough for you. But for iOS you could use the XCode Profiler.


Thanks for the response Terry, I think you’ve helped me realize my problem is how I’m managing memory. I’m changing scenes just like you are and not retaining anything so that narrows it down.

I think the issue is with a for loop and creating multiple sprites.