Memory Leak : not removing nodes recursively


photo

Recommended Posts

Hello,

I am currently using the Unigine C++ API version 2.6.1 and at some point I clone the root node of a reference by calling

reference->getReference()->clone();

This node's children has NodeDummy children. When I remove all the cloned node's (direct) children, the dummies are still in the world but not managed by the editor.

Here is how I remove them :

for (int i = node->getNumChildren() - 1; i >= 0; i--)
{
  auto child = node->getChild(i);
  node->removeChild(child);
  child->grab();
  child.clear();
}

This means that there's a memory leak. Because the "grandchildren" are not deleted/removed.

Anyone has any idea how to solve this problem?

 

Thanks in advance

Link to post

I managed to solve this issue by recursively "grabbing" the node and it's children using the following function :

void grabNodeRecursively(const Unigine::NodePtr& node)
{
  node->grab();
  for (int i = node->getNumChildren() - 1; i >= 0; i--)
  {
    grabNodeRecursively(node->getChild(i));
  }
}

Thanks anyways

Link to post

Hi Karim,

This is expected behavior for the old SDKs. In the newest versions you can simply replace grab() with deleteLater().

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to post