Code crashes at iteration 86

空扰寡人 提交于 2019-12-02 00:10:54

The kernel doesn't immediately garbage collect TreeNode objects. Once you are done with a treenode for an application object and all it's children, you need to call TreeNode.treeNodeRelease(), followed by treeNode=null; to let the garbage collector clean up.

...
TreeNode treeNodeToRelease;
...

while(treenode)
{

    ... /* do stuff with treenode */

    if(treeNodeToRelease && SysTreeNode::isApplObject(treeNode))
    {
        treeNodeToRelease.treeNodeRelease();
        treeNodeToRelease=null;
    }
    if(SysTreeNode::isApplObject(treeNode))
    {
        treeNodeToRelease=treeNode;
    }
    treeNode=iter.next();
}

The code:

 if(treeNodeToRelease && SysTreeNode::isApplObject(treeNode))

should be replaced by:

 if (treeNodeToRelease)

The release of the object should not depend on the next object.

or maybe this is enough (supplanting Jay's solution):

while (treenode)
{
    ... /* do stuff with treenode */
    treeNode.treeNodeRelease();
    treeNode = iter.next();
}

Quote from the manual:

If you run this method (treeNodeRelease()) on many tree nodes in the same execution, it can be demanding on resources. You should unload the tree nodes as you go along to give the garbage collector a chance to remove them.

Make sure to remove all references to the tree node and its subnodes before you call this method.

Also you have at least 85 references of the treeNodeToRelease (and treeNode!) floating around -> call treeNodeToRelease.treeNodeRelease() at the end of your outer loop.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!