[vtkusers] Memory not free - also with smartpointer
HaraldWeichenb
haraldweichenberger at gmx.at
Sun Sep 13 06:08:27 EDT 2009
Hi @all
I am new in using vtk.
I try to show an 3D-Structure with the following code.
This code is in a dll with i opened from an delphi-program.
If a open the following Sourcecode my memory grows at about 30MB. If i close
it, there are about 10MB left.
This program should be re-opened many times, so that my memory grows at
about 900MB at one day.
I allready try to find the problem for 2 weeks.
I hope you can help me!
Thanks!
int VTK3DOnlyVisual(long int* *PointerArrayIntLocal, float*
*PointerArraySingleLocal)
{
#define VTK_3DStructFiltersCREATE(type, var) \
vtkSmartPointer<type> var;
//*****
some variables are declerated here
PointerArrayIntLocal and PointerArraySingleLocal are arrays
of pointers
some arrays are declerated here and filled with the data
from the beginning of the pointers
//*****
VTK_3DStructFiltersCREATE(vtkDoubleArray,
textureIndex[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkPolyData,
poly[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkFloatArray,
TCoords[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkLookupTable,
lut[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkIntArray,
scalars[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkDoubleArray,
NormalArray[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkPoints,
points[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkCellArray,
polys[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkPolyDataMapper,
polyMapper[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkPolyDataMapper,
polyLineMapper[3]);
VTK_3DStructFiltersCREATE(vtkActor,
polyActor[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkActor, LineActor[3]);
VTK_3DStructFiltersCREATE(vtkLineSource, line[3]);
VTK_3DStructFiltersCREATE(vtkSmoothPolyDataFilter,
Smooth[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkFillHolesFilter,
fill[NumberOfStructs+1]);
VTK_3DStructFiltersCREATE(vtkCallbackCommand,
CallbackCommand);
CallbackCommand=vtkSmartPointer<vtkCallbackCommand>::New();
VTK_3DStructFiltersCREATE(vtkCallbackCommand,
CallbackKeyCommand);
CallbackKeyCommand=vtkSmartPointer<vtkCallbackCommand>::New();
VTK_3DStructFiltersCREATE(vtkTextProperty, TProp);
TProp=vtkSmartPointer<vtkTextProperty>::New();
VTK_3DStructFiltersCREATE(vtkProperty, pro);
pro=vtkSmartPointer<vtkProperty>::New();
VTK_3DStructFiltersCREATE(vtkRenderer, ren);
ren=vtkSmartPointer<vtkRenderer>::New();
VTK_3DStructFiltersCREATE(vtkLight, Light);
Light=vtkSmartPointer<vtkLight>::New();
VTK_3DStructFiltersCREATE(vtkCamera, cam1);
cam1=vtkSmartPointer<vtkCamera>::New();
VTK_3DStructFiltersCREATE(vtkInteractorStyleTrackballCamera, Style);
Style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
vtkRenderWindow* renWin=vtkRenderWindow::New();
VTK_3DStructFiltersCREATE(vtkRenderWindowInteractor, iren);
iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
for (int u=0; u<3; u++)
{
line[u]= vtkSmartPointer<vtkLineSource>::New();
polyLineMapper[u]=
vtkSmartPointer<vtkPolyDataMapper>::New();
LineActor[u]= vtkSmartPointer<vtkActor>::New();
}
for (int i=0; i<=NumberOfStructs; i++)
{
textureIndex[i]=vtkSmartPointer<vtkDoubleArray>::New();
Smooth[i]=
vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
poly[i]=vtkSmartPointer<vtkPolyData>::New();
TCoords[i]=vtkSmartPointer<vtkFloatArray>::New();
lut[i]=vtkSmartPointer<vtkLookupTable>::New();
scalars[i]=vtkSmartPointer<vtkIntArray>::New();
NormalArray[i]=vtkSmartPointer<vtkDoubleArray>::New();
points[i]=vtkSmartPointer<vtkPoints>::New();
polys[i]=vtkSmartPointer<vtkCellArray>::New();
polyMapper[i]=vtkSmartPointer<vtkPolyDataMapper>::New();
polyActor[i]=vtkSmartPointer<vtkActor>::New();
}
//***
Fill the Points, polys and poly
Fill the poly with TCoords, Normals and Colors in the LUT
//***
for (int i=0; i<=NumberOfStructs; i++)
{
polyMapper[i]->SetLookupTable(lut[i]);
polyMapper[i]->SetInput(poly[i]);
polyMapper[i]->SetScalarRange(0,n_Polys[i] -1);
polyActor[i]->SetMapper(polyMapper[i]);
polyActor[i]->GetProperty()->SetOpacity(transp[i]);
}
WinSizeHigh=WindowOpt[1];
WinSizeWidth=WindowOpt[0];
iren->SetRenderWindow(renWin);
cam1->SetPosition(glEyePosX,glEyePosY,glEyePosZ);
cam1->SetFocalPoint(IsoCtrX,IsoCtrY,IsoCtrZ);
cam1->SetWindowCenter(offsetX,offsetY);
cam1->SetViewUp(UpX,UpY,UpZ);
cam1->SetClippingRange(zNear,zFar);
cam1->SetViewAngle(CamAngle);
ren->SetActiveCamera(cam1);
Light->SetPosition(IsoCtrX,IsoCtrY,IsoCtrZ+dist);
Light->SetAmbientColor(ambientR,ambientG,ambientB);
Light->SetDiffuseColor(difuseR,difuseB,difuseG);
Light->SetSpecularColor(specularR,specularG,specularB);
Light->SetLightTypeToHeadlight();
Light->SetFocalPoint(cam1->GetFocalPoint());
Light->SetPosition(cam1->GetPosition());
Light->SetIntensity(1.5);
for (int i=0; i<=NumberOfStructs; i++)
{
ren->AddActor(polyActor[i]);
}
ren->AddLight(Light);
ren->SetBackground(0.99,0.99,0.99);
renWin->AddRenderer(ren);
renWin->SetWindowName("VTK-Visualisation-Release1");
renWin->SetPosition(WindowOpt[2],WindowOpt[3]);
renWin->SetSize(1,1);
renWin->BordersOff();
iren->SetInteractorStyle(Style);
iren->Initialize();
#ifdef WIN32
int borderHigh, borderWidth;
vtkWin32OpenGLRenderWindow *renWinCast =
static_cast<vtkWin32OpenGLRenderWindow *>(renWin);
HWND handle = renWinCast->GetWindowId();
SetWindowPos(handle, HWND_TOPMOST, WindowOpt[2],
WindowOpt[3],WinSizeWidth, WinSizeHigh, 0);
#endif
int ID;
iren->AddObserver(vtkCommand::TimerEvent, CallbackCommand ); // At
the moment i do nothing in DoStuff
CallbackCommand->SetCallback( DoStuff);
int timhandle = iren->CreateRepeatingTimer(200);
iren->AddObserver(vtkCommand::KeyPressEvent, CallbackKeyCommand );
// At the moment i do nothing in DoKeyCommand
CallbackKeyCommand->SetCallback( DoKeyCommand);
WindowOpen=1;
ren->Render();
iren->Start();
WindowOpen=0;
renWin->Delete();
return 0;
}
--
View this message in context: http://www.nabble.com/Memory-not-free---also-with-smartpointer-tp25421998p25421998.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list