Memory Management
Posted: Thu Oct 21, 2010 2:08 pm
I'm a newbie to Chipmunk and trying to use it for the first time in an iPhone game. Would like a few clarifications on the Memory allocation and release of the various structs. I went over Alexandre Gomes' tutorial on getting started with Chipmunk, but in his example code none of the structs are every released / deallocated. Wont this lead to a memory leak at some stage?
1) Assume a cpShape is allocated and initialized (eg using cpCircleShapeNew()) and attached to a cpBody. After attaching, if we free the shape using cpShapeFree() then would this affect the behaviour of the cpBody?
2) Would calling cpSpaceFree() on the space also free up all the attached bodies / shapes / joints to that space?
I'm confused regarding how the reference count of each struct is affected when it is attached / removed to another struct ... please shed some light on this.
1) Assume a cpShape is allocated and initialized (eg using cpCircleShapeNew()) and attached to a cpBody. After attaching, if we free the shape using cpShapeFree() then would this affect the behaviour of the cpBody?
2) Would calling cpSpaceFree() on the space also free up all the attached bodies / shapes / joints to that space?
I'm confused regarding how the reference count of each struct is affected when it is attached / removed to another struct ... please shed some light on this.