[vtkusers] garbage collection issues (was Java vtk wrapper memory/garbage collection issues.)
Denis Barbier
bouzim at gmail.com
Wed Dec 16 06:51:07 EST 2009
On 2009/12/15 Luke Dodd wrote:
> Hi,
>
> I'm having a number of issues with memory management/garbage
> collection of vtk objects when using the Java wrappers. The issues
> broadly fall under early deletion, although the second issue seems
> more subtle than this. I think they could be linked so I'll keep them
> both in one message.
>
> Firstly I think I have uncovered a bug, or at least behaviour I didn't
> expect. When (in Java code) a vtkAlgorthmOutput is held, but the
> corresponding vtkAlgorithm java wrapper object that it came from no
> longer has any references to it (for example goes out of scope) the
> vtkAlgorithm has it's Delete() method called upon java garbage
> collection/finalization. The issue is that after this the native
> vtkAlgorithm object seems to deleted. So if something tires to use the
> vtkAlgorithmOutput this will in turn probably mean trying to access
> the vtkAlgorthm which is now gone (for example on pipeline execution).
[...]
Hi Luke,
There are indeed severe issues with Java, I am also interested to know
if people successfully build large applications with VTK+Java.
Anyway, your first bug does not seem related to Java (I changed the
subject to have a broader audience), here is the same test-case in
C++, and it crashes at the same place. Did I make something wrong, or
is there some issues with reference counting?
#include <vtkAlgorithm.h>
#include <vtkAlgorithmOutput.h>
#include <vtkGeometryFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkSmartPointer.h>
vtkAlgorithmOutput* method(vtkAlgorithm* algorithm)
{
vtkSmartPointer<vtkGeometryFilter> gf2 =
vtkSmartPointer<vtkGeometryFilter>::New();
gf2->SetInputConnection(algorithm->GetOutputPort());
// Uncommenting this "fixes it"
//gf2->SetReferenceCount(gf2->GetReferenceCount()+1);
return gf2->GetOutputPort();
}
int main(int, char*[])
{
// loop block seems to crash about 50% of the time, loop 100
times to make sure it does
for(int i = 0; i < 100; i++)
{
//create a filter chain of gf1 and gf2, let gf2
vtkAlgorithm go out of scope
vtkSmartPointer<vtkGeometryFilter> gf1 =
vtkSmartPointer<vtkGeometryFilter>::New();
vtkAlgorithmOutput *gf2o = method(gf1);
// attempt to use gf2 via it's output port.
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(gf2o);
}
}
Denis
More information about the vtkusers
mailing list