0

I am experimenting with exporting the AOT CUS layer as an XPO file. Reference this question. I've run the excellent suggestions from the answers to said question but I am running into "out of memory" issues. I've done some further research and some additional experimentation. Here is a sample of the algorithm I am using to climb down the AOT tree and export only nodes that belong to the "CUS" layer.

private void GetAOLHelper(TreeNode baseNode, str baseExportDirectory, int currentLevel, int maxLevel)
{
    int cusLayerTest;
    int CusLayerValue = 4096;
    str ExportFileName = "";
    str ExportDirectoryName = "";
    TreeNode nextNode;

    if (baseNode != null)
    {
        cusLayerTest = CusLayerValue & baseNode.applObjectLayerMask();
        if (cusLayerTest > 0)
        {
            ExportFileName = baseNode.AOTname() + ".xpo";
            this.NodeExport(baseNode, baseExportDirectory, ExportFileName);
        }
        else
        {
            if (currentLevel < maxLevel)
            {
                nextNode = baseNode.AOTfirstChild();
                while (nextNode != null)
                {
                    this.GetAOLHelper(nextNode, baseExportDirectory, currentLevel + 1, maxLevel);
                    nextNode = nextNode.AOTnextSibling();
                }
                nextNode = null;
            }
        }
    }
}

The crux of this algorithm is as follows: I want to climb down the AOT tree (starting at a particular node) and export any layer that is a "CUS" layer object. I stop climbing down the tree at "maxlevel", meaning I only go X levels deep into the tree. I'm currently only running this algorithm on the "Data Dictionary" node of the AOT tree.

The issue I'm facing is that when this job runs, the memory footprint of the AX32.exe process is almost 1 GB. If I run this code against multiple nodes the memory requirement keeps climbing. I'm curious as to why AX is not releasing the memory when the algorithm is finished. My research on Google is coming up with some issues with the AX garbage collection. I'd like to know if there is a way to force garbage collection in AX? If I attempt to export every node in the AOT I run into the aforementioned "Out Of Memory" exception. The memory will not be released until I close the AX32.exe client.

Community
  • 1
  • 1

1 Answers1

3

TreeNode objects are not garbage collected like most other object. You have to release it yourself. Call treeNodeRelease()when you're done with a node.

Björn Olievier
  • 311
  • 2
  • 6
  • Thank you! I think the release helped a bit but my memory requirements are still extremely high. I'm wondering if when I do the nextnode = nextnode.AOTnextSibling() if it is losing the reference to the object. My memory is only 970 MB intead of 1 GB so the treenoderelease is freeing up SOME memory. –  Mar 07 '13 at 17:01
  • @ScottVercuski You're probably right that `nextSibling()` is the cause. You could try using a `TreeNodeIterator` object to get the child nodes instead of the loop you have now. Then you can call `treeNodeRelease()` for each nextNode. There's a method `AOTIterator()` on the Treenode class to get the iterator. – Björn Olievier Mar 08 '13 at 10:02
  • oddly enough I called nextNode.treeNodeRelease() right BEFORE I called nextNode.AOTnextSibling() and the node was fine. I was expecting it to be null but it worked and released the memory. It's a fairly counter-intuitive name as I expected treeNodeRelease to actually destroy the node but that doesn't seem to be the case. It seems that is just sets it up to be released when the garbage collector comes around. –  Mar 08 '13 at 14:59