[vtkusers] Delete on vtkPolyDataReader

Patric.Weis at mycrona.de Patric.Weis at mycrona.de
Wed Nov 15 03:17:04 EST 2000


Hi Francis,

You wrote:
> I want to deallocate the reader, but if I do so, my
> temporary variable points a wrong memory place
That's the destiny of temporary variables! :o)
Delete PolyDataReader only after your last access to its output. So use
PolyDataReader->Delete() at the end of your loop when you are leaving the
scope. In your code snippet you do not really need this confusing temporary
pointer. It simply points to PolyDataReader->GetOutput(), and this is not a
copy of it.

> When I delete the reader, how can I still keep the
> generated PolyData?
Let your reader alive and use its output to hold your polydata. In a loop
you could use an array of vtkPolyDataReader pointers to delete them outside
of your loop (e.g. vtkVoidArray or std::vector).
If you really need a polydata clone, try vtkPolyData::DeepCopy() to get an
identical polydata object.

> Can somebody explain me the correct way to use New()
> and Delete() statements in this case?
> ...
> This question concerns also vtkPolyData when it is
> constructed through a SetPoints():
> Shall I delete the vtkPoints AND the PolyData,
> or only the PolyData (since it includes the vtkPoints)
Using Delete() only marks(!) the object to be deleted as soon as possible.
So long as other vtk objects (e.g. your PolyData) need the object (e.g.
your vtkPoints), it never will be deleted and its pointer will still be
valid. By means of the reference count concept vtk does the deletion
automatically for us.

In your case: Mark vtkPoints with Delete() after having used SetPoints()
and if you are sure that you do not need it anymore. Then it will be
automatically deleted by vtk when you delete the PolyData it belongs to.


Hope this helps!

Patric


Patric Weis
MYCRONA GmbH


- - - Original Message - - -


                                                                                                                                        
                    "Francis Bouchet"                                                                                                   
                    <francis.bouchet at areall     An:     <vtkusers at public.kitware.com>                                                   
                    .com>                       Kopie:                                                                                  
                    Gesendet von:               Thema:  [vtkusers] Delete on vtkPolyDataReader                                          
                    vtkusers-admin at public.k                                                                                             
                    itware.com                                                                                                          
                                                                                                                                        
                    14.11.00 18:27                                                                                                      
                                                                                                                                        


   Hello,

   I'm working with vtk 3.1 on NT4.0 SP4 / Visual C++ 6.0.
   I have problems with memory deallocations.

   For instance, in the following example, I use a vtkPolyDataReader, and I
   want to use the resulting vtkPolyData.
   I first get the output of the reader in a temporary vtkPolyData
   variable,
   and then I want to deallocate the reader, but if I do so, my temporary
   variable points a wrong memory place :

   ----------------------------------------------------------------------------

   --------------------

   vtkPolyDataReader *PolyDataReader = vtkPolyDataReader::New();
   vtkPolyData *PolyData;

   PolyDataReader->SetFileName(FileName);
   PolyData =  PolyDataReader->GetOutput();
   PolyData->Update();
   PolyDataReader->Delete();
   printf("pts read : %d\n", PolyData->GetNumberOfPoints() );


   ----------------------------------------------------------------------------

   --------------------

   In order to avoid this problem, I can choose not to deallocate the
   reader,
   but in this case my program doesn't end properly.
   (This code lines are actually in a loop, and this function is supposed
   to be
   executed many times, and after a lot of iterations the program crashes
   on a
   New() or a Delete() statements.

   Can somebody explain me the correct way to use New() and Delete()
   statements
   in this case?
   When I delete the reader, how can I still keep the generated PolyData?
   This question concerns also vtkPolyData when it is constructed through a
   SetPoints() :
   Shall I delete the vtkPoints AND the PolyData, or only the PolyData
   (since
   it includes the vtkPoints) ?

   Could somebody help me please ?

   Thank you,

   Francis.


   _______________________________________________
   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://public.kitware.com/mailman/listinfo/vtkusers








More information about the vtkusers mailing list