[vtkusers] A Question about VTK for Java: Where is the Delete method? How to free RAM?

Julian Ibarz julian.ibarz at gmail.com
Mon Jun 16 09:27:03 EDT 2008


In Java the "destroy" method is called finally and is present on
vtkObjectBase (it calls the  VTK Delete method). If you look at the garbage
collector the java vtk objects are deleted (you say no but what have you
done to know there is java objets that are not destroyed ?) and there is no
memory leak in the java side, so theorically there is no memory leak at all
if the JNI code is nice coded.

But I have a memory leak in a complexe program that do the same thing than
you but in another program that require a lot of construction/destruction of
objets there is no memory leak so I think it's possible there is a leak in
the C++ parts on some classes (in my case I think vtkExtractSelectedFrustum
does a leak).

You have to take care about two points :

The java garbage collector works with allocation in java. If you construct a
vtkPolyData with 1 million of triangle, in the java side the object will
take a little of memory (less than 1Ko) but in the native parrt it will take
a lot of Mo. So the garbage will not destroy him because it's unecessary (it
not sees the native allocation parts). So to force the destruction you have
to call it explicitely : System.gc(); and the objet will be destroyed.

The vtkGarbageCollector does not destroy the weak reference of the vtk
objects even if they are destroyed (the weak reference becomes null but is
not destroyed). This is a memory leak but a very little memory leak that
does not make problem (a weak reference take a very little size of memory).

In conclusion, on my tests it's seems that the java side is clean, that in
certain case there is no memory leak so the JNI seems to not have memory
leak (because if the memory leak is on the JNI code it have to be memory
leak always) and the fault is surely in the C++ parts but it's not sure at
all.

2008/6/14 Oscar Javier Chavarro Garcia <oj.chavarro184 at uniandes.edu.co>:

> Hello all.
>
> I'm just a newbie, sorry if this question is too obvious or in the wrong
> list.
>
> I'm using the marching cubes filter in Java, and the program works fine
> when testing small volumes. Big volumes exceeds my RAM capacity (4GB), so I
> made a cycle to break my volume in parts and call several times the marching
> cubes algorithm to obtain partial polygon meshes which I glue together later
> on. For the first few chunks in this process goes fine, until the program
> dies because of insufficient memory.
>
> I have noticed that objects are not getting garbage-collected, no matter
> how I tried to decrease their reference count. I've called
> vtkGarbageCollector.Collect, vtkObjectBase.UnRegister, vtkObject.FastDelete
> in several forms with no luck. Java wrapped VTK seems to have the
> vtkObjectBase.Delete method missing.  How do I free RAM from unused objects?
>
> -Oscar Chavarro-
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>


-- 
Julian Ibarz



-- 
Julian Ibarz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080616/e39502e5/attachment.htm>


More information about the vtkusers mailing list