[vtkusers] java memory

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon Apr 4 12:09:21 EDT 2011


Hi Mark,

> Is there a recommended frequency for calling that garbage collector?

It will mainly depend on the usage that you are doing and if you know (or think)
that it will be worth it to release some memory.

> Are you suggesting that the garbage collector should be locked prior
> to calling, so that some other thread cannot interfere with it?

Right. The Garbage collector should make sure that none of the
building thread is currently working and once that garbage collector
is running, it must prevent any other building thread from working.

> What happens if another thread allocates memory when the garbage
> collector is running, will that cause a crash or stability problems?

It could depending of the dependency of object involved.

> The problem is that, while it doesn't look like the calls to
>
>   vtkPointData pointData = image.GetPointData();
>   vtkDataArray scalars = pointData.GetScalars();
>   scalars.FillComponent(0, 0);
>
> should allocate memory (since there are no 'news'), apparently, they
> do.  If I'm following the results of that properly, that means you're
> suggesting is to essentially halt vtk calls while the garbage
> collection is happening.  Am I correct in that?
>
> Would it be reasonable to expect that the following modification to
> Jon's code would be very unstable, since the main thread is creating
> memory while the EDT could be deleting it?

Yes but if you call InvokeAndWait instead of InvokeLater, you solve
that part of the problem as you are locking your current building
thread and you are forcing it to be in sync with the EDT during that
call.
Although, Jonathan said he has 2 building thread, not just one, so it
won't be as simple as that. That's why I talked about locks.

> Does this problem, or others like it, show up if I switch to Qt?

With Qt you have to be very careful as well. The only difference is
that you won't have to deal with in-between object to delete. But you
will definitely have the multi-threading issue to manage when you
delete vtk components.

Seb



More information about the vtkusers mailing list