Skip to content

Fix memory leak when input dataset changes

From patch contributed in #17609 by @BetaRavener.

A new subarray is added to GlyphValues map every time there is a new dataset object. The map is only cleared when mapper is destroyed.

The problem is, this works with plain VTK as the dataset doesn't really change between invocations of render, it may be only filled with different data. However, in some applications, such as ParaView, the actual dataset may be changing frequently. When that happens, we have the GlyphValues map storing a separate subarray and subsequently whole vtkOpenGLGlyph3DHelper for each uniqiue dataset and the entries don't get ever cleared until the whole vtkOpenGLGlyph3DMapper is destroyed. Of course vtkOpenGLGlyph3DHelper is storing some OpenGL resources, most notably Index Buffer Objects, so overall we hog not only CPU but also GPU memory.

This fix is based on the fact that these data sets stored in the map are really not valid anymore. So we just iterate the map and look for data set objects that have ReferenceCount <= 1 and delete those. Why? Because we know for sure that vtkOpenGLGlyph3DMapperEntry - child of the subarray (second item in map tuple), will be holding reference to the dataset. If it is needed elswhere, there will at least be another reference somewhere. Therefore, the dataset is valid in the mapper if it has at least 2 references. If there is only one reference, it's the vtkOpenGLGlyph3DMapperEntry who is holding it so it's safe to delete the entry.

Closes #17609

Merge request reports