[vtkusers] java memory

Mark Roden mmroden at gmail.com
Mon Apr 4 11:23:47 EDT 2011


Hi Sebastien,

Is there a recommended frequency for calling that garbage collector?
Are you suggesting that the garbage collector should be locked prior
to calling, so that some other thread cannot interfere with it?

What happens if another thread allocates memory when the garbage
collector is running, will that cause a crash or stability problems?
The problem is that, while it doesn't look like the calls to

   vtkPointData pointData = image.GetPointData();
   vtkDataArray scalars = pointData.GetScalars();
   scalars.FillComponent(0, 0);

should allocate memory (since there are no 'news'), apparently, they
do.  If I'm following the results of that properly, that means you're
suggesting is to essentially halt vtk calls while the garbage
collection is happening.  Am I correct in that?

Would it be reasonable to expect that the following modification to
Jon's code would be very unstable, since the main thread is creating
memory while the EDT could be deleting it?


import vtk.*;
public class VTKMemoryLeak {
    static {
        System.loadLibrary("vtkCommonJava");
        System.loadLibrary("vtkFilteringJava");
        System.loadLibrary("vtkGenericFilteringJava");
        System.loadLibrary("vtkGraphicsJava");
        System.loadLibrary("vtkHybridJava");
        System.loadLibrary("vtkImagingJava");
        System.loadLibrary("vtkIOJava");
        System.loadLibrary("vtkRenderingJava");
        System.loadLibrary("vtkVolumeRenderingJava");
        System.loadLibrary("vtkWidgetsJava");
        System.loadLibrary("vtkgdcmJava");
    }

    public static void main(String[] args) {
        for (int i=0; i<15; i++) {
            vtkImageData image = new vtkImageData();
            int[] extent = {0, 511, 0, 511, 0, 255};
            double[] origin = {0, 0, 0};
            double[] spacing = {1, 1, 3};
            image.SetExtent(extent);
            image.SetOrigin(origin);
            image.SetSpacing(spacing);
            image.SetScalarTypeToShort();
            image.AllocateScalars();
            vtkPointData pointData = image.GetPointData();
            vtkDataArray scalars = pointData.GetScalars();
            scalars.FillComponent(0, 0);
            InvokeLater(vtkGlobalJavaHash.GC());//some 'runnable'
version of this line so that the EDT invokes GC
        }
    }
}


Does this problem, or others like it, show up if I switch to Qt?

Thanks,
Mark



More information about the vtkusers mailing list