Hi, I am trying to understand how to manage textures.
Unlike many objects, textures do not have a create function. I assumed this meant that I could go ahead and manage the memory of the textures I create myself, but this seems not to be the case.
Therefore, I create a texture object within the context of one of my layers that lives as long as the scene is active, but is automatically freed when the layer is freed.
This seems to cause memory issues when the layer is freed.
Specifically, there is an issue during the call to CC_SAFE_RELEASE(_texture) within a sprite that uses the texture. In X_CODE, I get a memory error at this point (I’m assuming because i have already freed the texture, but I am not sure). I only get this issue when shutting down my application, which I assume means it comes because the texture is freed when the layer is removed, but before the sprites are freed by the custom garbage collection system.
- Why is the sprite trying to release a texture that I created and didn’t give it ownership of?
- Is the texture somehow an autorelease object, even though it is not called using a create macro?
- Could we use a standard memory management convention, such as smart pointers, rather than all of this custom memory management code? I find this very confusing and hard to wrap my head around when I have to manage the memory vs. the framework doing it for m.
Any thoughts on what I might be doing wrong here?