[vtkusers] Internal data source memory leak
Kit Chambers
kit.chambers.kc at gmail.com
Thu Dec 15 11:57:01 EST 2016
Thanks Utkarsh, I had originally discounted things like SetInputData() and SetInputDataObject() because I was getting errors related to WHOLE_EXTENT. However, I now think those errors are symptomatic of other issues I need to fix, as opposed to reinventing the wheel.
Kit
> On 15 Dec 2016, at 13:16, Utkarsh Ayachit <utkarsh.ayachit at kitware.com> wrote:
>
> Kit,
>
> vtkAlgorithm already supports API such as SetInputDataObject(...).
> Isn't that sufficient in your case?
>
> Utkarsh
>
> On Thu, Dec 8, 2016 at 9:50 AM, Kit Chambers <kit.chambers.kc at gmail.com> wrote:
>> Hi,
>>
>> For a variety of reasons I want to write a VTK filter which can take it input from a connection or an internal data source. I have come up with a method that works, but it is showing up a memory leak when i run with VTK_DEBUG_LEAKS=ON.
>>
>>
>> Essentially I have a data source which looks something like this:
>>
>> class vtkDataSource : public vtkImageAlgorithm
>> {
>> public:
>> …. blah blah …
>>
>> //! Set the internal data source
>> virtual int SetInputData(vtkImageData* data)
>> {
>> this->InternalData=data;
>> this->Modified();
>> return 1;
>> }
>> protected:
>> vtkDataSource(){
>> this->SetNumberOfInputPorts(0);
>> this->SetNumberOfOutputPorts(1);
>> this->InternalData=nullptr;
>> }
>>
>> ~vtkDataSource(){}
>>
>> int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *){
>>
>> if(this->InternalData==nullptr){
>> vtkErrorMacro("no input data");
>> return 0;
>> }
>> vtkSmartPointer<vtkImageData> outData = vtkImageData::GetData(outputVector);
>> outData->ShallowCopy(this->InternalData);
>> return 1;
>> }
>> private:
>> vtkSmartPointer<vtkImageData> InternalData;
>> };
>>
>> And then I have a filter which looks like this:
>>
>> class vtkInternalDataSourceFilter : public vtkImageAlgorithm
>> {
>> public:
>> … blah blah ...
>>
>> //! Set the internal data source
>> virtual int SetInputData(vtkImageData* data)
>> {
>> this->InternalData = vtkSmartPointer<vtkDataSource>::New();
>> this->InternalData->SetInputData(data);
>>
>> // This line triggers the memory leak
>> this->SetInputConnection(0,this->InternalData->GetOutputPort(0));
>> this->Modified();
>> return 1;
>> }
>> protected:
>> vtkInternalDataSourceFilter(){
>> this->SetNumberOfInputPorts(1);
>> this->SetNumberOfOutputPorts(1);
>> }
>> ~vtkInternalDataSourceFilter(){}
>>
>> int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *){
>> vtkSmartPointer<vtkImageData> input = vtkImageData::GetData(inputVector[0],0);
>> … do something …
>> return 1;
>> }
>> private:
>> vtkSmartPointer<vtkDataSource> InternalData;
>> };
>>
>>
>> You then run the filter using
>>
>> vtkSmartPointer<vtkInternalDataSourceFilter> flt = vtkSmartPointer<vtkInternalDataSourceFilter>::New();
>> flt->SetInputData(Img);
>> flt->Update();
>>
>> Specifically I get
>>
>> vtkDebugLeaks has detected LEAKS!
>> Class "vtkDataSource" has 1 instance still around.
>> Class "vtkCellData" has 2 instances still around.
>> Class "vtkInformationIntegerVectorValue" has 3 instances still around.
>> Class "vtkInformationVector" has 4 instances still around.
>> Class "vtkPointData" has 2 instances still around.
>> Class "vtkCompositeDataPipeline" has 1 instance still around.
>> Class "vtkPoints" has 2 instances still around.
>> Class "vtkInformation" has 16 instances still around.
>> Class "vtkInformationIntegerPointerValue" has 2 instances still around.
>> Class "vtkIdList" has 2 instances still around.
>> Class "vtkDoubleArray" has 2 instances still around.
>> Class "vtkAlgorithmOutput" has 1 instance still around.
>> Class "vtkInformationIntegerValue" has 32 instances still around.
>> Class "vtkImageData" has 2 instances still around.
>> Class "vtkFloatArray" has 1 instance still around.
>> Class "vtkInformationStringValue" has 1 instance still around.
>> Class "vtkInformationExecutivePortVectorValue" has 1 instance still around.
>> Class "vtkVoxel" has 2 instances still around.
>> Class "vtkFieldData" has 2 instances still around.
>> Class "vtkCommand or subclass" has 2 instances still around.
>> Class "vtkInformationExecutivePortValue" has 1 instance still around.
>>
>> however if I run everything normally it works fine.
>>
>> // Create a data source
>> vtkSmartPointer<vtkDataSource> src = vtkSmartPointer<vtkDataSource>::New();
>> src->SetInputData(Img);
>> src->Update();
>>
>> vtkSmartPointer<vtkInternalDataSourceFilter> flt = vtkSmartPointer<vtkInternalDataSourceFilter>::New();
>> lt->SetInputConnection(0,src->GetOutputPort(0));
>> flt->Update();
>>
>>
>> Any help would be appreciated and apologies for the large amount of code in this message.
>>
>>
>> Kit
>>
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list