robosuite icon indicating copy to clipboard operation
robosuite copied to clipboard

Fix: Prevent GPU memory leak by ensuring sim destruction on reset

Open kywch opened this issue 8 months ago • 2 comments

Hello, thank you for maintaining the awesome robosuite!

What this does

I've experienced a GPU memory leak while running a long session with many resets. I found that self._destroy_sim() was not being called during reset because my renderer was mjviewer.

With self._destroy_sim() properly called in each reset regardless of the renderer, I no longer see the GPU memory leak.

How it was tested

I monitored nvidia-smi during my script before and after the fix.

Thanks!

kywch avatar May 14 '25 19:05 kywch

Here is a simple test script to demonstrate the problem. With the current code, memory usage fluctuates up to 2GB. With the fix, memory usage remains constant at around 260MB.

import robosuite

env = robosuite.make("Lift", robots=["Panda"], has_offscreen_renderer=True)

while True:
    env.reset()
    sim_ref = env.sim
    for _ in range(100):
        env.step([0] * 7)

Thanks!

kywch avatar May 22 '25 17:05 kywch

you saved me. I wasn't able to train more than 100,000 steps, and find out this was the problem.

hochanb avatar Nov 23 '25 09:11 hochanb