[vtkusers] java memory

Jonathan Morra jonmorra at gmail.com
Tue Mar 29 03:41:53 EDT 2011


Sorry, forgot one more.  Should I be calling vtkGlobalJavaHash.GC() from the
event dispatch thread?  I saw that as an option in vtkJavaGarbageCollector,
and I'm not sure why that's the case.

On Mon, Mar 28, 2011 at 11:33 PM, Jonathan Morra <jonmorra at gmail.com> wrote:

> Thanks.  Since I'm using vtkJavaGarbageCollector I'm already using
> vtkGlobalJavaHash.GC();.  The main questions that I currently still need
> answered are here
> 1.  hould I have to call System.gc(); and System.runFinalization();
> frequently with VTK+Java?  It appears the memory is managed better when
> calling these lines every time vtkGlobalJavaHash.GC() is called, but I
> don't know if this is necessary.
> 2.  Is it ok to reuse Java variables?  Such as
>
> vtkImageData image = filter.GetOuput();
>
> // Do Stuff
>
> image = filter2.GetOuput();
>
> 3.   Is it OK to move around java objects without an intermediate
> reference?  Such as
> image1.SetOutputSpacing(image2.GetSpacing());
>
> Thanks for all your help!
>
> On Mon, Mar 28, 2011 at 6:54 PM, Sebastien Jourdain <
> sebastien.jourdain at kitware.com> wrote:
>
>> Hi Jonathan,
>>
>> Did I say Java reference count ? I think I was talking about the C++
>> layer that use reference count to delete unused VTK object. Depending
>> on the way you are doing things in Java, you can messed up that count
>> and therefore the vtkObject never get deleted as the C++ layer thinks
>> that reference is still used somewhere else.
>>
>> Regarding some of your questions (please ask them again if I miss some
>> in a single mail) here are some concept that are behind.
>>
>> If you call a method GetXXX() which return an object that has been
>> defined in the VTK library (in the C++ layer), you must use an
>> intermediate variable before assigning it to another SetXXX() vtk
>> object method.
>> Remarque: Java method name should have there first letter in lower
>> case which is not the case for the VTK ones. That could help to know
>> when you should do what.
>>
>> Moreover, to clear the VTK object associated to the Java ones, you do
>> need to call
>>
>> vtkGlobalJavaHash.GC();
>>
>> Otherwise they never get released. This is to prevent thread crash in
>> using VTK inside a multi-threaded java application. I mean by that, it
>> is the responsibility of the developer to call that method at the
>> right time as VTK is not thread safe.
>>
>> Good luck,
>>
>> Seb
>>
>>
>> On Mon, Mar 28, 2011 at 9:24 PM, Jonathan Morra <jonmorra at gmail.com>
>> wrote:
>> > Sorry for the barrage of questions, but I am really excited to get this
>> > working.  Is it OK to move around java objects without an intermediate
>> > reference?  Such as
>> > image1.SetOutputSpacing(image2.GetSpacing());
>> >
>> > On Mon, Mar 28, 2011 at 6:18 PM, Jonathan Morra <jonmorra at gmail.com>
>> wrote:
>> >>
>> >> Also, is it ok to reuse Java variables?  Such as
>> >> vtkImageData image = filter.GetOuput();
>> >> // Do Stuff
>> >> image = filter2.GetOuput();
>> >>
>> >>
>> >> On Mon, Mar 28, 2011 at 5:19 PM, Jonathan Morra <jonmorra at gmail.com>
>> >> wrote:
>> >>>
>> >>> Should I have to call System.gc(); and System.runFinalization();
>> >>> frequently with VTK+Java?
>> >>>
>> >>> On Mon, Mar 28, 2011 at 5:05 PM, Jonathan Morra <jonmorra at gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> OK, can you explain what you mean by Java reference count?  Here's
>> some
>> >>>> example code that doesn't seem to be working well.  Every time I run
>> it I
>> >>>> seem to accumulate memory I don't want.  Also, I'm using
>> >>>> vtkJavaGarbageCollector
>> >>>>         vtkLinearExtrusionFilter extruder = new
>> >>>> vtkLinearExtrusionFilter();
>> >>>>         extruder.SetInput(data);
>> >>>>         extruder.Update();
>> >>>>         vtkPolyData extruderOutput = extruder.GetOutput();
>> >>>>         vtkPolyDataToImageStencil pol2Stenc = new
>> >>>> vtkPolyDataToImageStencil();
>> >>>>         pol2Stenc.SetTolerance(0);
>> >>>>         pol2Stenc.SetInput(extruderOutput);
>> >>>>         pol2Stenc.SetInformationInput(binaryOrgan);
>> >>>>         pol2Stenc.Update();
>> >>>>         vtkImageStencilData pol2StencOutput = pol2Stenc.GetOutput();
>> >>>>         vtkImageStencil stencil = new vtkImageStencil();
>> >>>>         stencil.SetInput(binaryOrgan);
>> >>>>         stencil.ReverseStencilOn();
>> >>>>         stencil.SetStencil(pol2StencOutput);
>> >>>>         stencil.Update();
>> >>>>         final vtkImageData stencilOutput = stencil.GetOutput();
>> >>>>
>> >>>>             return stencilOutput;
>> >>>> On Mon, Mar 28, 2011 at 4:58 PM, Sebastien Jourdain
>> >>>> <sebastien.jourdain at kitware.com> wrote:
>> >>>>>
>> >>>>> Hi Jonathan,
>> >>>>>
>> >>>>> You should start by reading that thread.
>> >>>>>
>> >>>>> http://markmail.org/thread/k3u7gvsqwkocwfo5
>> >>>>>
>> >>>>> Seb
>> >>>>>
>> >>>>> On Mon, Mar 28, 2011 at 7:44 PM, Jonathan Morra <jonmorra at gmail.com
>> >
>> >>>>> wrote:
>> >>>>> > I've been working with Java for a while now and can't seem to get
>> my
>> >>>>> > memory
>> >>>>> > usage under control.  Is there anyone out there who's an expert in
>> >>>>> > VTK+Java
>> >>>>> > or at the very least has dealt with extensive memory usage in Java
>> >>>>> > with VTK
>> >>>>> > that could give me some advice or some reading material.
>> >>>>> > Thanks
>> >>>>> > _______________________________________________
>> >>>>> > 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
>> >>>>> >
>> >>>>> > Follow this link to subscribe/unsubscribe:
>> >>>>> > http://www.vtk.org/mailman/listinfo/vtkusers
>> >>>>> >
>> >>>>> >
>> >>>>
>> >>>
>> >>
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110329/e7009b12/attachment.htm>


More information about the vtkusers mailing list