google-deepmind / google-deepmind/mujoco
Memory leak in mjs_delete when detaching a body
- Dominant language
- C++
- Stars
- 15.2k
- Forks
- 1.8k
- Avg merge
- 10d 16h
- Merged PRs (30d)
- 25
Description
### Intro
Hi!
I am a PhD student at Zhejiang University. I use MuJoCo for my research on legged locomotion.
I use massively parallel environments for reinforcement learning with procedural terrain generation. After upgrading MuJoCo from 3.3.3 to 3.3.4 (which version replaces `mjs_detachBody` with `mjs_delete`), I found that a continuous memory leak occurs that had never happened before. I checked the source of MuJoCo and found that in version 3.3.3, `mjs_detachBody` calls `model->Detach(body);`, where `subtree->Release();` is invoked.
https://github.com/google-deepmind/mujoco/blob/f978b4eea368450267dd5e8825347653bec7355e/src/user/user_model.cc#L844C1-L850C1
However, after version 3.3.4, the implementation is moved to `void mjCModel::operator-=(mjsElement* el)`, where the `subtree->Release();` is removed. If I manually add `subtree->Release();`, the memory leak is fixed.
https://github.com/google-deepmind/mujoco/blob/8de86c9944e17efd04a3972a630a79a7da30736e/src/user/user_model.cc#L750C1-L757C6
Do I use the api in the wrong way? Or is this indeed a bug?
### My setup
MuJoCo 3.3.3 - 3.3.6 C version
### What's happening? What did you expect?
Memory leak.
### Steps for reproduction
Simple code for reproduction may be hard to provide.
### Minimal model for reproduction
_No response_
### Code required for reproduction
_No response_
### Confirmations
- [x] I searched the [latest documentation](https://mujoco.readthedocs.io/en/latest/overview.html) thoroughly before posting.
- [x] I searched previous [Issues](https://github.com/google-deepmind/mujoco/issues) and [Discussions](https://github.com/google-deepmind/mujoco/discussions), I am certain this has not been raised before.
Contributor guide
Assessment
This issue has not been assessed yet.