Hi,
In my code I use ODE collisions with the space.collide method instead of the Panda’s AutoCollide feature. Recently I’ve noticed a memory leak at the rate of up to 0.1 MB per second.
I’ve searched for the problem, and tracked it down to my collision handling task. After commenting almost everything in there, I was only left with the space.collide() method, yet the problem remained. This method uses a callback which I replaced with an empty method for testing.
However, as soon as I commented space.collide() as well, the problem seemed to no longer exist.
My tracking the cause of the leak might not be perfect, and the cause might still lie somewhere in my code (which I will continue to investigate), but currently I’m almost certain that either the collide method itself or my usage of it is the problem.
You can see the sample of the leak in here: dl.dropbox.com/u/196274/coppertopLeak.tar.gz
There’s not much going on in this sample when you run it, because the only thing the ODE update task does is invoke the space.collide() method, which in turn calls an empty callback. The most relevant code is odeWorldManager.py from line 810 to 822.
Note that for this simple demo it takes a while (at least on my system) for the leaking to manifest itself. If nothing happens (as in constant memory usage), try waiting a few minutes. Also, the leak is slower, but present.
The problem doesn’t (seem to) show when using the standard AutoCollide, which is yet another clue that it might be space.collide() related, because AutoCollide uses ODE’s functions directly, omitting space.collide().
I’ve tried to look into odeSpace.cxx for clues. I’m not into C++, but I was thinking it might be related to the near_callback method at line 260 of that file. It looks like the geoms are coppied there. The odespace_cat.spam() also looks a little suspicious to me, but as I said, I’m not good in C++, so it’s just a thought that came to my mind when browsing the source.
Just in case, I’m on 32-bit Ubuntu 10.04 and use the packages from the Panda’s ppa.
Thanks very much in advance for any help (even if only running to confirm) on this.
EDIT:
For testing purposes, I’ve replaced space.collide() call in the code I work on with this:
def spaceCollide(self):
numGeoms = self.space.getNumGeoms()
for i in range(numGeoms):
for j in range(numGeoms):
if i == j:
continue
g1 = self.space.getGeom(i)
g2 = self.space.getGeom(j)
self.handleCollisions("", g1, g2)
def simulationTask(self, task):
#self.space.collide("", self.handleCollisions)
self.spaceCollide()
self.world.quickStep(self.stepSize)
self.contactGroup.empty()
The rest of the code remained unchanged (including def handleCollisions which is normally used as callback in space.collide). Everything works (far too slowly, obviously) and the leak is not present in this setup.
I wanted to dive into the code of the space.collide, but I need instructions to correctly build ODE for use with Panda, so I can in turn build Panda myself. The package included with Ubuntu causes problems, rendering ODE unusable. If you can provide me with those directions I would be very grateful.
Peter