[vtkusers] vtkRenderer.RemoveActor() not removing actor?

Shyam Prakash ramakrishna.prakash at quest-global.com
Fri Nov 28 07:15:20 EST 2003


Phil,
	I tried your program on Win 2K and it works fine for me. The
actors are getting garbage collected. If you want a quick result, try
forcing System.gc() as soon you exit the for loop.

--Shyam

> -----Original Message-----
> From: vtkusers-admin at vtk.org [mailto:vtkusers-admin at vtk.org] On Behalf
Of
> Phil Cook
> Sent: Friday, November 28, 2003 5:32 PM
> To: vtkusers at vtk.org
> Subject: [vtkusers] vtkRenderer.RemoveActor() not removing actor?
> 
> I have a problem where I can't release the memory used by my actors
> after calling vtkRenderer.RemoveActor(vtkActor). As far as I can see,
> there aren't any other references to the actor around.
> 
> I modified SimpleVTK.java to illustrate the problem. I am using Java
on
> Linux, with yesterday's CVS VTK. When running this program and
watching
> top, I see the memory footprint grow whenever I press the button. It
> will grow far beyond the maximum Java stack size, so I think the
> problem is in the native code. Is there a safe way to delete the
actor?
> 
> Thanks,
> 
> 
> Phil
> 
> 
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import vtk.*;
> 
> 
> public class TestMemoryLeak extends JPanel implements ActionListener {
> 
>      static JFrame frame;
>      vtkPanel renWin;
>      JButton addRemoveActors;
> 
>      // We will remove add this to the renderer, then remove it
> repeatedly
>      vtkActor coneActor = new vtkActor();
> 
>      static {
>          System.loadLibrary("vtkCommonJava");
>          System.loadLibrary("vtkRenderingJava");
>      }
> 
> 
> 
>    public TestMemoryLeak() {
>      setLayout(new BorderLayout());
> 
>      renWin = new vtkPanel();
>      vtkConeSource cone = new vtkConeSource();
>      cone.SetResolution(60);
>      vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
>      coneMapper.SetInput(cone.GetOutput());
> 
>      coneActor.SetMapper(coneMapper);
> 
>      renWin.GetRenderer().AddActor(coneActor);
> 
>      addRemoveActors = new JButton("Add more actors");
>      addRemoveActors.addActionListener(this);
> 
>      add(renWin, BorderLayout.CENTER);
>      add(addRemoveActors, BorderLayout.SOUTH);
>    }
> 
> 
>      public void actionPerformed(ActionEvent e)
>      {
>          if (e.getSource().equals(addRemoveActors))
>              {
> 
>                  for (int i = 0; i < 1000; i++) {
> 
>                      renWin.GetRenderer().RemoveActor(coneActor);
> 
>                      vtkConeSource cone = new vtkConeSource();
>                      cone.SetResolution(60);
>                      vtkPolyDataMapper coneMapper = new
> vtkPolyDataMapper();
>                      coneMapper.SetInput(cone.GetOutput());
> 
>                      // this overwrites the reference to coneActor,
>                      // so shouldn't it be garbage collected?
> 		 // if you call coneActor.GetReferenceCount() here, it
returns
> 1
>                      coneActor = new vtkActor();
> 
>                      coneActor.SetMapper(coneMapper);
> 
>                      renWin.GetRenderer().AddActor(coneActor);
>                  }
>              }
>      }
> 
>    public static void main(String s[])
>    {
>      TestMemoryLeak panel = new TestMemoryLeak();
> 
>      frame = new JFrame("TestMemoryLeak");
>      frame.addWindowListener(new WindowAdapter()
>        {
>          public void windowClosing(WindowEvent e) {System.exit(0);}
>        });
>      frame.getContentPane().add("Center", panel);
>      frame.pack();
>      frame.setVisible(true);
>    }
> }
> 
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list