Search code examples
xmlactionscript-3apache-flexhttpservice

Effective way to update XMLListCollection


I have the following code:

private var xmlC:XMLListCollection = new XMLListCollection();
private var httpS:HTTPService = new HTTPService();
private var timer:Timer = new Timer(1000);
private var xmlData:XML;
private var xmlDataList:XMLList;

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
    httpS.url = "data.xml";
    httpS.addEventListener(ResultEvent.RESULT, resultHTTP);
    httpS.resultFormat="e4x";
    httpS.send();

    timer.start();
    timer.addEventListener(TimerEvent.TIMER, updateXMLC);
}

private function updateXMLC(event:TimerEvent):void
{
    xmlC.source = xmlDataList;
    httpS.send();
}

private function resultHTTP(event:ResultEvent):void
{
    xmlData = event.result as XML;
    xmlDataList = xmlData.dg.rows.row;
}

"data.xml" have 5000 lines, so I need to clean its traces whenever necessary. I have two problems that I found thanks to the profiling

  1. Every time httpS.send() is called in the method updateXMLC, it calls URLLoader internally which keeps XML that is not needed anymore wandering in the memory without being garbage collected
  2. is there a more effective way to update xmlC, whenever the XMLListCollection is updated, it seems that the previous value of XMLListCollection doesn't get garbage collected

Solution

  • Seems it was a bug in Flex framework: