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