开发者

Code crashes at iteration 86

static void Job47(Args _args)
 {
 str                                  path,stx;
 TreeNodeIterator                     iter;
 TreeNode                开发者_JAVA技巧             treeNode, treeNodeToRelease;
 Map                                  dictMenuDisplay;
 FormName                             formName;
 MenuItemName                         menuItemName;
 container                            conMenu;
 int                                  i,n;
   ;

 for (n=1;n<=100;n++)
       {
        info(strfmt("iter:%1",n));
        path            ="Menu Items\\Display";
        dictMenuDisplay = new Map(Types::String,Types::Container);
        treenode        = Treenode::findNode(path);
        iter            = treenode.AOTiterator();
        treenode        = iter.next();

        while (treenode)
          {
          formName     = treenode.AOTgetProperty("Object");
          menuItemName = treenode.AOTname();

           if (dictMenuDisplay.exists(formName))
            {
             conMenu = dictMenuDisplay.lookup(formName);
             conMenu = conIns(conMenu,conlen(conMenu)+1,menuItemName);
             dictMenuDisplay.insert(formName,conMenu);
             }

           else
             dictMenuDisplay.insert(formName,[menuItemName]);
                      //  treenode = iter.next();

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

           if(SysTreeNode::isApplObject(treeNode))
            {
              treeNodeToRelease=treeNode;
            }

            treeNode=iter.next();
        }
    }
  }

I get the error "overflow in internal run stack",the code runs till 86th iteration correctly, help...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜