[vtkusers] Delete actor and release memory

Nicolas Rannou nicolas.lists at gmail.com
Wed Jul 6 15:20:42 EDT 2011


So it looks like I was deleting the mapper at the wrong position.
I was deleting it right after adding it to the actor.
Now I delete the mapper just before deleting the polydata.

The reference count for the polydata is correct now. (== 0 after deleting
the polydata)

But the reference count of the actor remains wrong and the memory usage
doesn't decrease.

for 1000 spheres:
->create polydatas, create mappers, create actors, add actors to renderer,
render,  remove actors from the renderer, delete actors, delete mappers,
delete polydatas
->render, start interaction: memory usage: *60Mb*
*(if I don't call render between adding/removing the actors, the memory
usage is reduced to 40Mb)*

->create polydatas, create mappers, create actors,
add actors to renderer, render, remove actors from the renderer,
->delete actors, delete mappers, delete polydatas
->render, start interaction: memory usage: *40Mb*
*
*
*
->create polydatas,
**

create mappers, create actors, add actors to renderer, render, remove actors
from the renderer, delete actors, delete mappers
**
,
*
*
->delete polydatas
*
->render, start interaction: memory usage: *20Mb*
*
*
The vtkSphereSource I use to generate my polydatas also has a wrong
(different from 0) ref count after deleting it.
(see code below. Full test code is available at: git at github.com:
NicolasRannou/spheres.git )

Nicolas

//----------------------------------------------------------------------
*
*
*
  vtkSphereSource* sphereSource = vtkSphereSource::New();
  sphereSource->SetRadius(0.3);

  for(int i=0;i<numberOfSpheres; ++i )
    {
    for(int j=0; j<numberOfSpheres; ++j)
      {
      for(int k=0; k<numberOfSpheres; ++k)
        {
        sphereSource->SetCenter(i, j, k);
        sphereSource->Update();

        // we work on a polydata to be in a minimalistic case
        vtkPolyData* polydata = vtkPolyData::New();
        polydata->DeepCopy(sphereSource->GetOutput());
        polydatas.push_back(polydata);

        vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
        mapper->SetInput(polydata);
        mapper->Update();
        mappers.push_back(mapper);

        vtkActor* actor = vtkActor::New();
        actor->SetMapper(mapper);
        actors.push_back(actor);

        renderer->AddActor(actor);
        }
      }
    }

  sphereSource->Delete();

//----------------------------------------------------------------------
*
*
*
*
*
On Wed, Jul 6, 2011 at 10:54 AM, Shashwath T.R. <trshash at gmail.com> wrote:

> I think I get it...
>
> 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).
>
> Shash
>
>
> On Wed, Jul 6, 2011 at 7:55 PM, Nicolas Rannou <nicolas.lists at gmail.com>wrote:
>
>> *Actor:*
>> create                       -> ref count == 1
>> add to renderer          -> ref count == 2
>> remove from renderer -> ref count == 1
>> delete                       -> ref count == 1576215064, -304508392, etc.
>>
>> *PolyData:*
>> create                                                                ->
>> ref count == 1
>> add to mapper                                                    -> ref
>> count == 3
>> add mapper to actor, add actor to renderer, render -> ref count == 5
>> remove actor from renderer, delete actor               -> ref count == 3
>> delete                                                                -> ref
>> count == 52101520, -304508392, etc.
>>
>> Something interesting I noticed is that if I do the same, without using
>> the renderer (adding/removing actors), the polydata ref count looks fine:
>>
>> *
>> Actor:
>> create                       -> ref count == 1
>> delete                       -> ref count == 1576215064, -304508392, etc.
>>
>> PolyData:
>> create                                                                ->
>> ref count == 1
>> add to mapper                                                    -> ref
>> count == 3
>> **
>> delete related actor                                             -> ref
>> count == 3
>> *
>> *
>> delete                                                                -> ref
>> count == 0
>> ***
>>
>>
>> I tried the vtk master and 5.6.1 tag from github.
>>
>> Thanks
>>
>>
>> On Tue, Jul 5, 2011 at 6:28 PM, Xiaofeng Z <xf10036 at hotmail.com> wrote:
>>
>>>   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.
>>>
>>> xz
>>>
>>>  *From:* Nicolas Rannou <nicolas.lists at gmail.com>
>>> *Sent:* Tuesday, July 05, 2011 9:10 AM
>>> *To:* Sebastien Jourdain <sebastien.jourdain at kitware.com>
>>> *Cc:* vtkusers at public.kitware.com
>>> *Subject:* Re: [vtkusers] Delete actor and release memory
>>>
>>> Hi Sebastien,
>>>
>>> Yes, I don't delete it on purpose.
>>>
>>> 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!
>>>
>>> Thanks
>>>
>>> Nicolas
>>>
>>> On Sat, Jul 2, 2011 at 11:19 PM, Sebastien Jourdain <
>>> sebastien.jourdain at kitware.com> wrote:
>>>
>>>> You never deleted the sphere.
>>>>
>>>> On Tue, Jun 28, 2011 at 5:56 PM, Nicolas Rannou <
>>>> nicolas.lists at gmail.com> wrote:
>>>> > Hi all,
>>>> > I would like to delete/remove actors from my rendering window to free
>>>> > memory.
>>>> > The issue is that the memory usage doesn't decrease after
>>>> removing/deleting
>>>> > the actors.
>>>> > From my understanding, both following pseudo-codes should use the same
>>>> > amount of memory.
>>>> > But,
>>>> > The first one uses: 15 Mb for 1000 spheres:
>>>> > The second uses: 90 Mb for 1000 spheres:
>>>> > How should I proceed in the 2nd case, to get back to the "original"
>>>> memory
>>>> > usage without actor?
>>>> > Thanks,
>>>> >
>>>> > Nicolas
>>>> > ______________________________
>>>> > 15 Mb
>>>> > ______________________________
>>>> > //Create a sphere
>>>> > vtkSphereSource* sphere = new ...
>>>> > ______________________________
>>>> > 90 Mb
>>>> > ______________________________
>>>> > //Create sphere
>>>> > vtkSphereSource* sphere = new ...
>>>> > // mapper
>>>> > vtkMapper* mapper ...
>>>> > mapper->SetInput( sphere->GetOutput() )
>>>> > // actor
>>>> > vtkActor* actor...
>>>> > actor->SetMapper(mapper)
>>>> > mapper->Delete()
>>>> > // Add and remove actor
>>>> > renderer->AddActor(actor)
>>>> > renderer->RemoveActor(actor)
>>>> > // Delete actor
>>>> > actor->Delete()
>>>> > ______________________________
>>>> > ______________________________
>>>> >
>>>> >
>>>> > _______________________________________________
>>>> > Powered by www.kitware.com
>>>> >
>>>> > Visit other Kitware open-source projects at
>>>> > http://www.kitware.com/opensource/opensource.html
>>>> >
>>>> > Please keep messages on-topic and check the VTK FAQ at:
>>>> > http://www.vtk.org/Wiki/VTK_FAQ
>>>> >
>>>> > Follow this link to subscribe/unsubscribe:
>>>> > http://www.vtk.org/mailman/listinfo/vtkusers
>>>> >
>>>> >
>>>>
>>>
>>>
>>> ------------------------------
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110706/c5fd555b/attachment.htm>


More information about the vtkusers mailing list