opensim-core: Memory leak during integration
I was trying to figure out why we get memory leaks in osim-rl. I use a slightly different custom version of osim-rl. However, it seems that everything points towards the integrate function of the Manager. The new version of the Manager does not have a reset mechanism and therefore one must delete the manager and create a new one. I have a minimum working example attached which demonstrates that memory increases. Could you please have a look and tell me if I miss something and if there is a way to figure out where the problem is?
For those who do not have time to run the code, you can find the code here:
#include <iostream>
#include <OpenSim/OpenSim.h>
#include "memory_usage.h"
using namespace OpenSim;
using namespace SimTK;
using namespace std;
int main(int argc, char *argv[])
{
auto model = Model("model_generic.osim");
auto state = model.initSystem();
auto manager = new Manager(model);
auto previous_size = getCurrentRSS();
auto i = 101;
while (true) {
if (i >= 100) {
i = 1;
state = model.initializeState();
model.equilibrateMuscles(state);
state.setTime(0);
cout << "manager will be deleted" << endl;
delete manager;
manager = new Manager(model);
manager->initialize(state);
}
manager->integrate(i * 0.01);
i++;
// check if memory usage increased
auto current_size = getCurrentRSS();
auto diff = current_size - previous_size;
previous_size = current_size;
if (diff != 0) {
cout << i << " " << diff * 1e-6 << "MB" << endl;
}
}
return 0;
}
Many thanks!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (21 by maintainers)
@adamkewley If the leak happens in public release 4.1 or earlier then you can rule out the logger since it has been rewritten in master branch, the old one didn’t use spdlog altogether. With the new logger you can turn it all off and see if the leaks remain but there was no such option for the old logger.
Nice job digging though and I’m interested to know if there’s an actual leak here indeed even if unrelated to the reported issue.