[vtkusers] VTK and Java Wrappers

Lars Matthäus lars.matthaeus at web.de
Thu Mar 25 03:36:07 EDT 2010


Dear Jeff,

I tested your solution, but I can't get it to work; either I have a
memory leak or a crash (or both). I have the following small test
program (see attachment for full compiling program):

int i = 0;
int k = 0;
while (true) {

	final vtkArrowSource arrowSource = new vtkArrowSource();
	final vtkPolyDataMapper mapper = new vtkPolyDataMapper();
	mapper.SetInput(arrowSource.GetOutput());
	final vtkActor actor = new vtkActor();
	actor.SetMapper(mapper);

	arrowSource.Delete();
	mapper.Delete();
	actor.Delete();

	++i;
	if (i >= 10000) {
		++k;
		vtkGlobalJavaHash.GC();
		System.out.println("" + k * 10000);
		i = 0;
	}
}

This program runs until it runs out of memory (>1.5GB). So neither
.Delete nor vtkGlobalJavaHash.GC() nor the "normal" Java gc seem to help.

If I delete the lines arrowSource.Delete(); mapper.Delete();
actor.Delete(); the program crashes when vtkGlobalJavaHash.GC(); is
called for the second or third time (log attached).

Without vtkGlobalJavaHash.GC() the program runs out of memory in both
cases (with and without .Delete on the vtk objects).

Any ideas?

Regards, Lars


Am 23.03.2010 16:41, schrieb Jeff Baumes:
> I have a patch resolving some of the issues raised, shown below with
> the commit message. Are there any objections to using features from
> Java 1.5 (the patch includes features from 1.5)? Any opinions on what
> the default behavior of VTK garbage collection should be (currently
> once a second on the event thread)?
> 
> http://github.com/jeffbaumes/VTK/commit/5418afd7b6430ded86f0c8746673ed19612b9a8b
> 
> ENH: Giving more control of VTK gc to developers.
> 
> The finalize() method has been removed from VTK objects, since
> finalize() is called on a different thread and may cause concurrency
> issues. Instead, we keep a hash table containing WeakReference's in
> vtkGlobalJavaHash. vtkGlobalJavaHash.GC() will call VTK's Delete() on
> any objects whose weak reference has expired (i.e. they have been
> garbage collected by Java). This may be called manually, or may be
> called at intervals on the swing event thread by an instance of
> vtkJavaGarbageCollector. The default currently is that it is called
> once every second on the swing event thread.
> 
> vtkGlobalJavaHash.DeleteAll() will delete all native objects in the
> hash table regardless of whether their Java objects are still in use.
> Therefore this should be reserved for when you will no longer use any
> VTK objects in Java, (e.g. at shutdown).
> 
> Also included is the fix to Bug 8942 submitted by dbarbier, where the
> Java hash could be corrupted when calling Delete manually on objects.
> 
> Some tests have been added that demonstrate how the new classes
> should work
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestVTKgc.java
Type: text/java
Size: 912 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100325/f729d48c/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: hs_err_pid4084.log
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100325/f729d48c/attachment.txt>


More information about the vtkusers mailing list