<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>You both were right.</div><div>I forgot to delete the mapper in switchRepresentationToSphere().</div><div>As you said David, I was deleting vtk objects myself and the vtksmartpointers allow to do it automaticly.</div><div>It's quite pleasant when the answer is so blatant isn't it ?!</div><div><br></div><div>Thanks you all.</div><div>Ben</div><div><br></div><div><br></div><div><div><div>Le 11 mai 10 à 02:38, da a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite">Youre not deleting mapper in switchRepresentationToSphere().<div><br></div><div>I doubt the "Leaks" in Apple instruments will be any use in this case. <br><br><div class="gmail_quote">On Mon, May 10, 2010 at 8:52 AM, Benoist Laurent <span dir="ltr"><<a href="mailto:benoist@ibpc.fr">benoist@ibpc.fr</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div style="word-wrap:break-word">Hi all,<div><br></div><div>I've got a problem for freeing memory with VTK 5.2.</div> <div>In my program, I've got a function that allows to switch between a line representation and a sphere representations.</div><div>Each time I switch, I pay attention to remove the actor from the renderer then delete the actor before initializing it again.</div> <div><br></div><div>But when I use Apple Instruments to check for memory leaks, I can see that there is not memory leak (good point) but that the memory usage increases every time I switch from lines to spheres (see picture).</div> <div><br></div><div>Does anyone have an idea of what am I doing wrong ?</div><div><br></div><div>Any help would be appreciated.</div><div>Thanks.</div><div>Ben.</div><div><br></div><div><br></div><div>Here is the code.</div> <div><br></div><div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">void switchRepresentationToLines()</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">{</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>deleteActor();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "> <span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>mapper->SetInput(_data);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "> <span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>_actor = vtkActor::New();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>_actor->SetMapper(mapper);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:13px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>_renderer->AddActor(_actor);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>updateDisplay();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "> <span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>mapper->Delete();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> }</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:13px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">void switchRepresentationToSpheres()</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">{</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>deleteActor();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>vtkSphereSource * sphereSource = vtkSphereSource::New();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>sphereSource->SetThetaResolution(10.0);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>sphereSource->SetPhiResolution(10.0);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>sphereSource->SetRadius(1.0);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "> <span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>vtkGlyph3D * glyph = vtkGlyph3D::New();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>glyph->SetInput(_data);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>glyph->SetSourceConnection(sphereSource->GetOutputPort());</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>glyph->SetVectorModeToUseNormal();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>glyph->SetScaleModeToScaleByVector();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>glyph->SetScaleFactor(0.5);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "><span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>mapper->ImmediateModeRenderingOn();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>mapper->SetInputConnection(glyph->GetOutputPort());</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "><span style="white-space:pre">        </span><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>_actor = vtkActor::New();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>_actor->SetMapper(mapper);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "><span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>_renderer->AddActor(_actor);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>updateDisplay();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 13px; "> <span style="white-space:pre">        </span><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>sphereSource->Delete();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>glyph->Delete();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">void deleteActor()</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>if (actor)</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>{</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>_renderer->RemoveActor(_actor);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>_actor->Delete();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>_actor = NULL;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>}<span style="white-space:pre">        </span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><img height="95" width="389"></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <br></div></div></div></div><br>_______________________________________________<br> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br> <br> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br> <br> Follow this link to subscribe/unsubscribe:<br> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br> <br></blockquote></div><br></div></blockquote></div><br></div></body></html>