Michael Buckley wrote:I should also point out that, in the context of my test code, I saw the exact same behavior with non-static shapes. The code simply creates a body, creates a space, and then loops through a set number of times, creates a new shape for the body, adds the shape to the space, removes it from the space, and frees the shape. Then, after the loop is complete, it sleeps for a while before exiting.
I don't know if the handles of non-static shapes would get released during the operation of a normal program.
I can only reproduce the leak when I add static shapes to the space (without rehash), not non-static.
This code uses more and more memory
Code: Select all
init_pymunk()
space = Space()
while True:
body = Body(1,1)
shape = Segment(body, vec2d(0, 0), vec2d(0, 0), 0.0)
space.add_static(shape)
space.remove_static(shape)
space.step(1.0/60)
This code doesn't
Code: Select all
init_pymunk()
space = Space()
while True:
body = Body(1,1)
shape = Segment(body, vec2d(0, 0), vec2d(0, 0), 0.0)
space.add(shape)
space.remove(shape)
space.step(1.0/60)
This code doesn't
Code: Select all
init_pymunk()
space = Space()
while True:
body = Body(1,1)
shape = Segment(body, vec2d(0, 0), vec2d(0, 0), 0.0)
space.add_static(shape)
space.resize_static_hash()
space.remove_static(shape)
space.step(1.0/60)
(everything from python with pymunk but I think you can read it
)
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app