[vtkusers] java memory

David Gobbi david.gobbi at gmail.com
Tue Mar 29 10:28:50 EDT 2011


Python uses a memory management scheme that is almost identical to
VTK, so they work together very nicely. Every variable, attribute, or
container element in Python acts like a smart pointer.  When a python
variable goes out of scope, the reference count is automatically
decremented.  Some of the nightly dashboard machines run the python
tests with DEBUG_LEAKS on, so we know that the system works reliably.

There is a "gc" module in python that can be used to query and control
the garbage collection system, but note that Python's GC works by a
completely different algorithm than Java's. Python will usually free
objects as soon as they go out of scope, its "scheduled" garbage
collection is just a sweeper to detect reference loops.

 - David


On Tue, Mar 29, 2011 at 7:36 AM, Sebastien Jourdain
<sebastien.jourdain at kitware.com> wrote:
> I bet not,
>
> but David Gobbi might be the best person to know if it's the case or not.
>
> Seb
>
> On Tue, Mar 29, 2011 at 9:16 AM, Lic. José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> those problems also apply to the python layer?
>>
>> On Tue, Mar 29, 2011 at 8:26 AM, Sebastien Jourdain
>> <sebastien.jourdain at kitware.com> wrote:
>>> Hi Jonathan,
>>>
>>> I directly reply on the context of your mail,
>>>
>>>
>>> On Tue, Mar 29, 2011 at 2:33 AM, Jonathan Morra <jonmorra at gmail.com> wrote:
>>>> Since I'm using vtkJavaGarbageCollector I'm already using
>>>> vtkGlobalJavaHash.GC();.  The main questions that I currently still need
>>>> answered are here
>>>> 1.  should 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.
>>>
>>> System.gc(); is the only one that you should really care about. But
>>> Java does not offer any guarantee if this method will do something or
>>> not.  Moreover, the GC will stop all the thread to do its job. So it
>>> is basically up to you.
>>>
>>>> 2.  Is it ok to reuse Java variables?  Such as
>>>> vtkImageData image = filter.GetOuput();
>>>> // Do Stuff
>>>> image = filter2.GetOuput();
>>>
>>> yes
>>>
>>>> 3.   Is it OK to move around java objects without an intermediate reference?
>>>>  Such as
>>>> image1.SetOutputSpacing(image2.GetSpacing());
>>>
>>> what do you mean by Java object ? for me as the Set/Get do have a
>>> capital letter, I would say they come from the VTK world and if they
>>> return a vtkObject, you should use an intermediate variable otherwise
>>> if it's an array of primary type, that is just fine.
>>>
>>>> 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.
>>>
>>> This totally depend on your VTK code, if you insure that all the call
>>> you are doing on the VTK layer is done through the EDT, then you
>>> should, otherwise you shouldn't. (This is a requirement if the data is
>>> shown in a renderer.)
>>>
>>> Seb
>>> _______________________________________________
>>> 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
>>>
>>
>>
>>
>> --
>> Lic. José M. Rodriguez Bacallao
>> Centro de Biofisica Medica
>> -----------------------------------------------------------------
>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
>>
>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>> por profesionales
>> -----------------------------------------------------------------
>>
>



More information about the vtkusers mailing list