Search code examples
memory-managementaxaptax++dynamics-ax-2012aot

Dynamics AX 2012 not releasing memory


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.


Solution

  • 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.