[vtkusers] Garbage collection and .NET problem

Serge Lalonde serge at infolytica.com
Wed Oct 22 16:44:46 EDT 2008


Hello all,

I have run into a problem caused by a conflict between the .NET garbage 
collection and the VTK garbage collection. However, I believe that this 
is a general problem that could occur when using Java or even C++ if a 
vtk object were deleted in a different thread.

Because certain objects require that they be freed in the main thread 
(actually the rendering thread) because they need to free OpenGL 
resources in their ReleaseGraphicResources() method (ex: 
vtkOpenGLTexture), they cannot be freed in the .NET garbage collection 
thread. Doing so causes an error in 
vtkWin32OpenGLRenderWindow::MakeCurrent() at line 218 when calling 
wglMakeCurrent() because the rendering context is not valid for this thread.

I did some digging and found 
vtkGarbageCollector::DeferredCollectionPush() that looked perfect. 
However, it unfortunately didn't work. There doesn't seem to be much 
documentation on this or in the mailing list.

1. Does anyone know what DeferredCollectionPush() does and what it is 
meant to actually fix?
2. Has anyone run into this problem and if so, how did you fix it?

Thanks.



More information about the vtkusers mailing list