[vtkusers] JVM Crashes while Call vtkGlobalJavaHash.DeleteAll() in Ubuntu...

Sebastien Jourdain sebastien.jourdain at kitware.com
Thu May 5 07:56:15 EDT 2011


I forget to say how to setup the Garbage collector.

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                vtkJavaGarbageCollector gc =
vtkGlobalJavaHash.GarbageCollector;
                gc.SetScheduleTime(1, TimeUnit.SECONDS);
                gc.SetAutoGarbageCollection(true);
                //gc.SetDebug(true);
                new MainApp().setVisible(true);
            }
        });
    }

On Wed, May 4, 2011 at 5:09 PM, Sebastien Jourdain <
sebastien.jourdain at kitware.com> wrote:

> Hi Sathish,
>
> after some digging on what was going on with your code, I've figured out
> that the memory leak you were facing while using the VTK garbage collector
> was mainly due to Java who keep a reference to any graphical components that
> have been shown at some point.
>
> And in your case, your graphical frame keep a reference to all your VTK
> objects (readers, filters, renderers...). And because of that, VTK could
> never release them.
>
> In order to solve your specific issue you have to have some code like that
> in your WindowClosed listener:
>
> private void formWindowClosed(java.awt.event.WindowEvent evt) {
>      this.myVtkObjectA = null;
>      // [...]
>      this.myVtkObjectZ = null;
>
>      // but also remove the content of you renderer that will keep
>      // the whole pipeline alive in the C++ layer if not cleared
>
>      this.myVtkPanel.RemoveAllViewProps();
>      this.myVtkPanel.GetRenderer().RemoveAllLights();
>
> this.myVtkPanel.GetRenderWindow().RemoveRenderer(this.myVtkPanel.GetRenderer());
> }
>
> As you may see for vtkPanel we have a similar issue where its internal
> component won't be released, and for now in order to reduce the memory leak
> you need to execute the lines that I've put above with "myVtkPanel".
>
> But in a near future, we will add a Delete() method on the vtkPanel to
> fully release its internal objects so the code block could be reduced to
> : this.myVtkPanel.Delete();
>
> Moreover, Jeff and I are working of documenting the Java part of VTK and
> providing some tools to help identifying the cause of memory leak in Java as
> well as improving the concurrency support/management. So if some community
> member has Java/VTK testing code that produce error/crash because of
> concurrency or memory leak that could be used as test, please send them to
> us so we can make sure that the improvement that we are making will solve
> your issue.
>
> Thanks,
>
> Seb
>
>
> On Wed, Apr 27, 2011 at 8:30 AM, Sebastien Jourdain <
> sebastien.jourdain at kitware.com> wrote:
>
>> Hi Sathish,
>>
>> Do you think you can share your source code (offlist) so I can give a look
>> and understand why you are facing this issue.
>>
>> Thanks,
>>
>> Seb
>>
>> On Wed, Apr 27, 2011 at 2:07 AM, Sathish kumar <kingvsk at aol.com> wrote:
>>
>>>   Hi Sebastien,
>>>
>>> Thanks for your response.
>>>
>>>     I developed a simple application that loads a list of dicom images
>>> and construct them as 3D.  It works fine. I call VTK from my Java
>>> Application. If I press a button from main window, then the VTK output will
>>> load in another Jframe window. Once I close the output window the VTK should
>>> release all the memory. But i doesn't do that. It will be released only when
>>> I close my main application. (Please refer the attachment).
>>>
>>> My Requirement is while I close the 3D window The VTK memory should be
>>> released.
>>>
>>>   With Regards,
>>>
>>> Sathish Kumar V
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110505/33855934/attachment.htm>


More information about the vtkusers mailing list