[osg-users] How to track down memory leaks?

Robert Osfield robert.osfield at gmail.com
Thu Jul 12 08:57:45 PDT 2018

Hi Igor,

On Thu, 12 Jul 2018 at 16:24, Igor Spiridonov <igwasm at rambler.ru> wrote:
> I have found the memory leak cause. Look like I don't understand how osg works.
> I have a root node and its child node. I add UpdateCallback to the root node and inside this callback i remove child nod's drawables and add another ones. I check reference count before I remove them and it's 2 for some reason. My remove decreases it on 1 but it's not enough. Looks like viewer or something else keeps these drawables and therefore memleak happens.
> I checked reference count of drawables after I add them to child's node and it's always 1 but when drawables come again to UpdateCallback it becomes 2.

The OSG's rendering backend retains a ref_ptr<> to the StateSet and
Drawables required for the current frame, but nothing beyond this.
It's not a memory leak at though, this is all cleaned up robustly.

If there is an actual leak in your program then perhaps you've created
a circular reference somewhere, could you have a child object, or
callback perhaps that holds a ref_ptr<> to a parent?


More information about the osg-users mailing list