So it looks like I was deleting the mapper at the wrong position.<div>I was deleting it right after adding it to the actor.</div><div>Now I delete the mapper just before deleting the polydata.</div><div><br></div><div>The reference count for the polydata is correct now. (== 0 after deleting the polydata)</div>
<div><br></div><div>But the reference count of the actor remains wrong and the memory usage doesn't decrease.</div><div><br></div><div>for 1000 spheres:</div><div>->create polydatas, create mappers, create actors, add actors to renderer, render, remove actors from the renderer, delete actors, delete mappers, delete polydatas</div>
<div>->render, start interaction: memory usage: <b>60Mb</b></div><div><b>(if I don't call render between adding/removing the actors, the memory usage is reduced to 40Mb)</b></div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8">->create polydatas, create mappers, create actors,</div>
<div><strike><font face="arial">add actors to
renderer, render, remove actors from the renderer</font></strike>,</div><div>->delete actors, delete mappers, delete polydatas</div>
<div>->render, start interaction: memory usage: <b>40Mb</b></div><div><b><br></b></div><div><b><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-weight: normal; "><div>
->create polydatas, </div></span></b><b><span class="Apple-style-span" style="font-weight: normal; "><div style="display: inline !important; "><p style="margin-bottom: 0in; font-style: normal; font-weight: normal; widows: 2; orphans: 2; display: inline !important; ">
<font color="#000000"><strike><font face="arial">create mappers, create actors, add actors to renderer, render, remove
actors from the renderer, delete actors, delete mappers</font></strike></font></p></div></span></b><b><span class="Apple-style-span" style="font-weight: normal; "><div style="display: inline !important; ">,</div></span></b></div>
<div><b><span class="Apple-style-span" style="font-weight: normal; "><div style="display: inline !important; ">->delete polydatas</div></span></b><div style="font-weight: normal; ">->render, start interaction: memory usage: <b>20Mb</b></div>
<div style="font-weight: normal; "><b><br></b></div><div>The vtkSphereSource I use to generate my polydatas also has a wrong (different from 0) ref count after deleting it.</div><div>(see code below. Full test code is available at: git@github.com:NicolasRannou/spheres.git )</div>
<div style="font-weight: bold; "><br></div><div>Nicolas</div></div><div><br></div><div>//----------------------------------------------------------------------</div><div><b><br></b></div><div><b><div> vtkSphereSource* sphereSource = vtkSphereSource::New();</div>
<div> sphereSource->SetRadius(0.3);</div><div><br></div><div> for(int i=0;i<numberOfSpheres; ++i )</div><div> {</div><div> for(int j=0; j<numberOfSpheres; ++j)</div><div> {</div><div> for(int k=0; k<numberOfSpheres; ++k)</div>
<div> {</div><div> sphereSource->SetCenter(i, j, k);</div><div> sphereSource->Update();</div><div><br></div><div> // we work on a polydata to be in a minimalistic case</div><div> vtkPolyData* polydata = vtkPolyData::New();</div>
<div> polydata->DeepCopy(sphereSource->GetOutput());</div><div> polydatas.push_back(polydata);</div><div><br></div><div> vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();</div><div> mapper->SetInput(polydata);</div>
<div> mapper->Update();</div><div> mappers.push_back(mapper);</div><div><br></div><div> vtkActor* actor = vtkActor::New();</div><div> actor->SetMapper(mapper);</div><div> actors.push_back(actor);</div>
<div><br></div><div> renderer->AddActor(actor);</div><div> }</div><div> }</div><div> }</div><div><br></div><div> sphereSource->Delete();</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-weight: normal; ">//----------------------------------------------------------------------</span></div>
</b></div><div><b><br></b></div><div><b><br></b></div><div><div class="gmail_quote">On Wed, Jul 6, 2011 at 10:54 AM, Shashwath T.R. <span dir="ltr"><<a href="mailto:trshash@gmail.com" target="_blank">trshash@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think I get it...<div><br></div><div>Try setting NULL as the input to the mapper before deleting it (I think you should also do this after removing from the renderer, so that you don't get a warning about trying to render an empty polydata, but I'm not so sure of this).</div>
<div><br></div><div>Shash<div><div></div><div><br><br><div class="gmail_quote">On Wed, Jul 6, 2011 at 7:55 PM, Nicolas Rannou <span dir="ltr"><<a href="mailto:nicolas.lists@gmail.com" target="_blank">nicolas.lists@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><b><u>Actor:</u></b></div>create -> ref count == 1<div>add to renderer -> ref count == 2</div><div>remove from renderer -> ref count == 1<br><div>delete -> <font color="#ff0000">ref count == 1576215064, -304508392, etc.</font></div>
<div><font color="#ff0000"><br></font></div><div><b><u>PolyData:</u></b></div><div>create -> ref count == 1</div><div>add to mapper -> ref count == 3</div>
<div>add mapper to actor, add actor to renderer, render -> ref count == 5</div><div>remove actor from renderer, delete actor -> ref count == 3</div><div>delete -> <span style="color:rgb(255, 0, 0)">ref count == 52101520, -304508392, etc.</span></div>
<div><span style="color:rgb(255, 0, 0)"><br></span></div><div>Something interesting I noticed is that if I do the same, without using the renderer (adding/removing actors), the polydata ref count looks fine:</div><div><br>
</div><div><div><b><span style="font-weight:normal"><div style="text-decoration:underline">
<b><u>Actor:</u></b></div>create -> ref count == 1<div><div>delete -> <font color="#ff0000">ref count == 1576215064, -304508392, etc.</font></div><div><font color="#ff0000"><br>
</font></div><div><b><u>PolyData:</u></b></div><div>create -> ref count == 1</div><div>add to mapper -> ref count == 3</div>
</div></span></b><b><span style="font-weight:normal"><div style="display:inline !important"><div style="display:inline !important">delete related actor -> ref count == 3</div>
</div></span></b></div><div><b><span style="font-weight:normal"><div style="display:inline !important"><div style="display:inline !important">delete -> <span style="color:rgb(255, 0, 0)">ref count == 0</span></div>
</div></span></b><b><span style="font-weight:normal"></span></b></div></div><div><br></div>
<div><br></div><div>I tried the vtk master and 5.6.1 tag from github.</div>
<div><br></div><div>Thanks</div><div><div></div><div><div><br></div><div><br><div class="gmail_quote">On Tue, Jul 5, 2011 at 6:28 PM, Xiaofeng Z <span dir="ltr"><<a href="mailto:xf10036@hotmail.com" target="_blank">xf10036@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div style="font-family:'Calibri';color:#000000;font-size:12pt">
<div>Does the memory location pointed by variable actor still contain a valid
object (e.g. reference count > 0) after actor->Delete()? If not,
then memory used by actor should have been released.</div>
<div style="font-style:normal;display:inline;font-family:'Calibri';color:#000000;font-size:small;font-weight:normal;text-decoration:none">
<div style="font:10pt tahoma">
<div><font size="3" face="Calibri"></font> </div>
<div><font size="3" face="Calibri">xz</font></div>
<div> </div>
<div style="background:#f5f5f5">
<div><b>From:</b> <a title="nicolas.lists@gmail.com" href="mailto:nicolas.lists@gmail.com" target="_blank">Nicolas Rannou</a> </div>
<div><b>Sent:</b> Tuesday, July 05, 2011 9:10 AM</div>
<div><b>To:</b> <a title="sebastien.jourdain@kitware.com" href="mailto:sebastien.jourdain@kitware.com" target="_blank">Sebastien Jourdain</a> </div>
<div><b>Cc:</b> <a title="vtkusers@public.kitware.com" href="mailto:vtkusers@public.kitware.com" target="_blank">vtkusers@public.kitware.com</a> </div>
<div><b>Subject:</b> Re: [vtkusers] Delete actor and release
memory</div></div></div>
<div> </div></div>
<div style="font-style:normal;display:inline;font-family:'Calibri';color:#000000;font-size:small;font-weight:normal;text-decoration:none"><div><div></div><div>Hi
Sebastien,
<div> </div>
<div>Yes, I don't delete it on purpose.
<div> </div>
<div>I would like to keep the polydata in memory but delete everything else
which is related to the visualization in order to decrease the memory
usage!</div>
<div> </div>
<div>Thanks</div>
<div> </div>
<div>Nicolas</div>
<div>
<div> </div>
<div class="gmail_quote">On Sat, Jul 2, 2011 at 11:19 PM, Sebastien Jourdain <span dir="ltr"><<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>></span>
wrote:<br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">You never deleted the sphere.<br>
<div>
<div></div>
<div><br>On Tue, Jun 28, 2011 at 5:56 PM, Nicolas Rannou <<a href="mailto:nicolas.lists@gmail.com" target="_blank">nicolas.lists@gmail.com</a>>
wrote:<br>> Hi all,<br>> I would like to delete/remove actors from my
rendering window to free<br>> memory.<br>> The issue is that the memory
usage doesn't decrease after removing/deleting<br>> the actors.<br>>
From my understanding, both following pseudo-codes should use the same<br>>
amount of memory.<br>> But,<br>> The first one uses: 15 Mb for 1000
spheres:<br>> The second uses: 90 Mb for 1000 spheres:<br>> How should I
proceed in the 2nd case, to get back to the "original" memory<br>> usage
without actor?<br>> Thanks,<br>><br>> Nicolas<br>>
______________________________<br>> 15 Mb<br>>
______________________________<br>> //Create a sphere<br>>
vtkSphereSource* sphere = new ...<br>>
______________________________<br>> 90 Mb<br>>
______________________________<br>> //Create sphere<br>>
vtkSphereSource* sphere = new ...<br>> // mapper<br>> vtkMapper* mapper
...<br>> mapper->SetInput( sphere->GetOutput() )<br>> //
actor<br>> vtkActor* actor...<br>> actor->SetMapper(mapper)<br>>
mapper->Delete()<br>> // Add and remove actor<br>>
renderer->AddActor(actor)<br>> renderer->RemoveActor(actor)<br>>
// Delete actor<br>> actor->Delete()<br>>
______________________________<br>>
______________________________<br>><br>><br></div></div>>
_______________________________________________<br>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>><br>> Visit other Kitware
open-source projects at<br>> <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:<br>> <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>><br></blockquote></div>
<div> </div></div></div>
</div></div><p>
</p><hr><div>
_______________________________________________<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></div><p></p></div></div></div></div>
</blockquote></div><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></div></div>
</blockquote></div><br></div>