Insufficient memory to run script

I have created a AIF service to export the data from ax 2012 to Dell Boomi. For small data size it is working fine but i am trying to export large data it is giving me the error " Insufficient memory to run script ".

[AifCollectionTypeAttribute(‘return’ ,Types::AnyType),SysEntryPointAttribute(true)]
public AifXml TransactionsXML_230()
{

XML xmlReturn; // xml extended data type declaration

XmlDocument doc;
XmlElement nodeXml;
XmlElement nodeTable;
XmlElement nodeAccount;
XmlElement nodeName;

doc = XmlDocument::newBlank();
nodeXml = doc.createElement(‘TRANSACTIONS’);
doc.appendChild(nodeXml);

//XML File Generation logic

doc.save(fileName); // converting to xml
//return “xyz”;
xmlReturn = doc.xml();
return xmlReturn;

}

the xml EDT String Size is (Memo) which can store a large amount of data. but still i am getting this error. for confirmation followed the bellow link https://community.dynamics.com/ax/f/33/t/216473 please give me any fix.

Moved from Dynamics 365 Forum to D365 for Finance and Operations developer forum.

You might want to look at my blog post about this error. It documents what I found about it and how.

In your case, the best option likely will be using several smaller messages instead of a single huge one.