[vtkusers] Reference Count = 2 after Constuctor

David Cole david.cole at kitware.com
Thu May 1 13:11:18 EDT 2008


It's because you are calling
  this->SetNumberOfInputPorts(0);
in your constructor. Your parent class sets it to 1.

When you call this, you get connected to the default executive that's
created by the parent class and form a "reference loop". This is ok and
expected, though.

If you call:
  vtkH5PolyDataReader* reader = vtkH5PolyDataReader::New();
  reader->Print(cout);
  reader->Delete();
your reader will be deleted even though in the middle it has a ref count of
2... Set breakpoints (or put "cout <<" stuff) in the constructor /
destructor for this simple case to prove it to yourself.


HTH,
David


On Mon, Apr 28, 2008 at 6:09 PM, Mike Jackson <imikejackson at gmail.com>
wrote:

> I have a class that I am writing that inherits from
> vtkPolyDataAlgorithm. After calling:
>
> vtkH5PolyDataReader* reader = vtkH5PolyDataReader::New();
> the reference count is 2. Shouldn't it be 1? I have another generic
> class the inherits from vtkObject and running the same basic test
> gives me a reference count of 1. What might be some reasons why my ref
> count is 2? I think this is causing other problems in my code.
>
> Here is my constructor:
>
> vtkCxxRevisionMacro(vtkH5PolyDataReader, "1.0");
> vtkStandardNewMacro(vtkH5PolyDataReader);
>
> vtkH5PolyDataReader::vtkH5PolyDataReader()
> {
>  this->FileName = NULL;
>  this->SetNumberOfInputPorts(0);
> }
>
> I also have the following in the header:
>
> public:
> static vtkH5PolyDataReader *New();
>
> protected:
>  vtkH5PolyDataReader();
>  ~ vtkH5PolyDataReader();
>
>
> Thanks for any help on this.
> --
> Mike Jackson
> imikejackson _at_ gee-mail dot com
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the 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/20080501/5eee315e/attachment.htm>


More information about the vtkusers mailing list