how to avoid leaks?
Posted: Wed Jul 16, 2008 12:06 pm
I'm experimenting with the SimTK 1.0 Linux Release binary and SimTKExamples1.0c.zip posted yesterday.
My interest is implementation of torsion angle dynamics in a crystallographic refinement program. Therefore I'm concentrating on ExampleSimpleProtein.cpp and the new adenylate_mobilities.1.0.cpp.
To get a quick idea of the code health, I'm checking for memory access problems and leaks.
In ExampleSimpleProtein.cpp I commented out the VTKEventReporter and shortened the simulation time to 2 seconds. I used valgrind (valgrind.org) to check for memory access problems. I'm happy to report that valgrind doesn't find any errors, which is very encouraging.
To check for memory leaks, I changed main() to work() and added a new main() calling work() in an endless loop. The complete code is below. While running the newly compiled executable, I'm checking the memory allocation of the process with the "top" command. It shows that the memory allocation is increasing steadily, suggesting that some objects instantiated in work() aren't destroyed properly. Do I need to add explicit cleanup code?
Thanks!
Ralf
P.S.: I'm using Fedora 8, which comes with gcc 4.1.2.
Modified ExampleSimpleProtein.cpp:
#include "SimTKmolmodel.h"
//#include "SimTKsimbody_aux.h" // for vtk visualization
using namespace SimTK;
using namespace std;
void
work()
{
CompoundSystem system; // molecule-specialized simbody System
SimbodyMatterSubsystem matter(system); // matter is required
TinkerDuMMForceFieldSubsystem dumm(system); // molecular force field
DecorationSubsystem artwork(system); // for drawing vtk visualization
dumm.loadAmber99Parameters();
Protein protein("SIMTK");
protein.assignBiotypes();
system.adoptCompound(protein);
system.updDefaultSubsystem();//.addEventReporter(new VTKEventReporter(system, 0.020));
system.modelCompounds(); // finalize multibody system
State state = system.realizeTopology();
// Simulate it.
VerletIntegrator integ(system);
TimeStepper ts(system, integ);
ts.initialize(state);
ts.stepTo(2.0);
}
My interest is implementation of torsion angle dynamics in a crystallographic refinement program. Therefore I'm concentrating on ExampleSimpleProtein.cpp and the new adenylate_mobilities.1.0.cpp.
To get a quick idea of the code health, I'm checking for memory access problems and leaks.
In ExampleSimpleProtein.cpp I commented out the VTKEventReporter and shortened the simulation time to 2 seconds. I used valgrind (valgrind.org) to check for memory access problems. I'm happy to report that valgrind doesn't find any errors, which is very encouraging.
To check for memory leaks, I changed main() to work() and added a new main() calling work() in an endless loop. The complete code is below. While running the newly compiled executable, I'm checking the memory allocation of the process with the "top" command. It shows that the memory allocation is increasing steadily, suggesting that some objects instantiated in work() aren't destroyed properly. Do I need to add explicit cleanup code?
Thanks!
Ralf
P.S.: I'm using Fedora 8, which comes with gcc 4.1.2.
Modified ExampleSimpleProtein.cpp:
#include "SimTKmolmodel.h"
//#include "SimTKsimbody_aux.h" // for vtk visualization
using namespace SimTK;
using namespace std;
void
work()
{
CompoundSystem system; // molecule-specialized simbody System
SimbodyMatterSubsystem matter(system); // matter is required
TinkerDuMMForceFieldSubsystem dumm(system); // molecular force field
DecorationSubsystem artwork(system); // for drawing vtk visualization
dumm.loadAmber99Parameters();
Protein protein("SIMTK");
protein.assignBiotypes();
system.adoptCompound(protein);
system.updDefaultSubsystem();//.addEventReporter(new VTKEventReporter(system, 0.020));
system.modelCompounds(); // finalize multibody system
State state = system.realizeTopology();
// Simulate it.
VerletIntegrator integ(system);
TimeStepper ts(system, integ);
ts.initialize(state);
ts.stepTo(2.0);
}