[vtkusers] [advice needed] - c++ memory management
Denis Barbier
bouzim at gmail.com
Fri Dec 18 07:25:11 EST 2009
On 2009/12/18 hampycalc wrote:
>
> Hi all,
>
> I am hoping to get a little advice for good coding practice in VTK. I have
> been creating some applications, but not been doing a very good job with my
> memory management. Could someone advise as to how to code the following
> situation:
> Simply, I have a FileIO class, and within a method taking a filename to a
> .vtk polydata file, and returning a vtkPolyData pointer. As you can see, I
> have not been very clever with my memory management (please see code
> below).... however, I have been banging my head against the monitor trying
> to find the most sensible way to do this.
> Presumably incrementing the reference count of the object returned by
> reader->GetOutput() (assigned to data) is going to have no effect when the
> reader->Delete() is called, so data->Register(NULL) or creating a
> smartpointer to data is not going to have any effect.
[...]
When looking for hints about reference counters in VTK, I found this page:
http://www.visitusers.org/index.php?title=Memory_Management
The first sample code is about this exact issue.
Denis
More information about the vtkusers
mailing list