I'm getting memory errors and it's probably because of a lack of understanding pointers. I have an instance variable in my game layer that is of a projectile class I made. The projectile has a box2d body and a CCsprite.
So every time a player shoots using an end touch a new projectile is created/assigned to the instance variable, box2d body and all. The reason I assign it to the instance variable is because I need access to that single projectile in other methods to aim and manipulate it for my game. I'm detecting collisions with the projectile, adding to a toDestroy array and removing the ccsprite and body from the scene. Every once in a while I get a memory error when I try to add a new projectile to the layer. Should I not be reusing the instance variable to create objects that remain in the scene?
My error happens occasionally when the game tries to add a new projectile body. Not sure how there is a memory issue creating something new.
Sorry I don't have code it would pretty much be the entire game. I'm more looking for programming concepts.
Any best practices I should follow to create, change and dispose of projectiles?