I'm trying to figure out how to delete the geometry shape objects. I've tried
many thing, but I have not been able to completely remove memory leaks. Below
is a sample code of what fails and how I am approaching the problem.
Thanks for all of your help.
#include "TROOT.h"
#include "TBRIK.h"
#include "TTUBE.h"
#include "TNode.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRotMatrix.h"
extern void InitGui();
VoidFuncPtr_t initfuncs[] = {InitGui, 0};
TROOT root("Test","Test",initfuncs);
void create_wire( TNode *topNode );
int main(int argc, char **argv) {
TBRIK *brick;
TNode *topNode;
TCanvas *c1;
TApplication geomApp("testApp", 0, NULL);
c1 = new TCanvas("c1","TestClass",500,500);
// This loop shows how memory usage grows.
for (int i = 0; i < 200000; i++) {
if ( i != 0 ) {
// How do I delete all of the existing geometry shape, node, and rotation
// matrix objects? I wish it would be as simple as the following line.
topNode->Delete();
// What seems to work best but still has leaks and causes core dumps is:
// TNode *node;
// TObject *obj;
// TIter next(topNode->GetListOfNodes());
// while ((obj = next())) {
// node = (TNode*)obj;
// node->GetShape()->Delete();
// node->Delete();
// }
// topNode->GetShape()->Delete();
// topNode->Delete();
}
brick = new TBRIK("invisible_brick","Brick","void",1.,1.,1.);
topNode = new TNode("topNode","TopNode",brick,0,0,0,0);
topNode->SetVisibility(2);
topNode->cd();
create_wire(topNode);
}
topNode->Draw();
c1->Update();
geomApp.Run();
return(0);
}
void create_wire( TNode *topNode ) {
TTUBE *wire;
TNode *node;
TRotMatrix *rot;
topNode->cd();
wire = new TTUBE("wire1","Wire","void",0.,1.,10.);
wire->SetLineColor(20);
rot = new TRotMatrix("rotate","Rotate",95.,10.,90.,100.,5.,10.);
node = new TNode("node1","Node2",wire,0.,0.,0.,rot);
}
Glen
*********************************************************************
Glen R. Salo g.r.salo@ieee.org
Mission Research Corporation (937)429-9261 Ext. 19
3975 Research Boulevard (937)429-2625 Fax
Dayton, Ohio 45430-2108
*********************************************************************