What I find is that while I am running my program, my memory usage, judged from watching the OS X "activity monitor", increases by about two megabytes per second. Moreover the game stutters every second or so in a way I am interpreting as slowdown from the game having to get more memory from the OS. And when the btCollisionWorld is deleted (this is happening, unless something very unexpected is going on, every time you die; I delete the btCollisionWorld and then recreate it) the memory is not reclaimed, the two-megabytes-per-second increase continues instantly from the exact amount of memory use I was taking before deleting the last btCollisionWorld.
Based on my initial tests I believe this apparent memory leak is happening "inside" of contactTest. If I comment out the call to contactTest, the memory increase no longer happens. If I comment out nearly everything I am doing *other* than calling contactTest, the memory leak is not abated.
I found this thread on the forum which recommends various things for debugging memory leaks. As it recommended, I commented in the define for BT_DEBUG_MEMORY_ALLOCATIONS in LinearMath/btAlignedAllocator.h and then attempted (my build process is funny :/) to recompile. I was unable to use _CrtDumpMemoryLeaks(); this appears to be a Windows-only function and I do not have Windows. What I could do, however, is
Code: Select all
extern int gNumAlignedAllocs, gNumAlignedFree, gTotalBytesAlignedAllocs;
ERR("ALLOCS %d FREE %d TOTAL %d\n", gNumAlignedAllocs, gNumAlignedFree, gTotalBytesAlignedAllocs);
Code: Select all
ALLOCS 564 FREE 221 TOTAL 0
ALLOCS 744 FREE 401 TOTAL 0
ALLOCS 924 FREE 581 TOTAL 0
ALLOCS 1104 FREE 761 TOTAL 0
ALLOCS 1284 FREE 941 TOTAL 0
ALLOCS 1464 FREE 1121 TOTAL 0
ALLOCS 1644 FREE 1301 TOTAL 0
ALLOCS 1824 FREE 1481 TOTAL 0
ALLOCS 2004 FREE 1661 TOTAL 0
ALLOCS 2184 FREE 1841 TOTAL 0
ALLOCS 2364 FREE 2021 TOTAL 0
ALLOCS 2544 FREE 2201 TOTAL 0
Code: Select all
ALLOCS 3138 FREE 2452 TOTAL 0
ALLOCS 3318 FREE 2632 TOTAL 0
ALLOCS 3498 FREE 2812 TOTAL 0
ALLOCS 3678 FREE 2992 TOTAL 0
ALLOCS 3858 FREE 3172 TOTAL 0
ALLOCS 4038 FREE 3352 TOTAL 0
ALLOCS 4218 FREE 3532 TOTAL 0
ALLOCS 4398 FREE 3712 TOTAL 0
Like I said I didn't write most of the Bullet interface code myself, instead getting it from the Polycode library, so I'm not 100% certain on how it works. And there might be any number of bugs in my code as well. However the bit of code which calls contactTest is isolated enough there doesn't seem to be space for me or Polycode to be introducing bugs, unless there is special magic to using contactTest I am doing wrong.
If it helps:
The (very simple) code from my game which calls contactTest is here
The (more complex) Polycode library code which sets up Bullet is here and here (headers here and here)
What should I do to debug from here?