after assigning loaded XML data to an array of objects, i would like to remove the XML from memory, or at least available to the garbage collector. however, doing so also removes the assigned object values in the array.
rather than calling XMLdata = null;
, i'm calling System.disposeXML(XMLData);
as directed by the documentation:
disposeXML() method: Makes the specified XML object immediately available for garbage collection. This method will remove parent and child connections between all the nodes for the specified XML node.
should i not be trying to dispose of the loaded XML data after assigning it to an array of objects?
//Convert XML Data To Array Of Objects
var XMLData:XML = XML(evt.currentTarget.data);
for each (var station:XML in XMLData.station)
{
var stationObject:Object = new Object();
stationObject.name = station.name;
arrayData.push(stationObject);
}
//Nullify XML
trace(XMLData == null); //false
trace(arrayData[0].name); //traces name
XMLData = null;
trace(XMLData == null); //true
trace(arrayData[0].name); //traces name
//Dispose XML
trace(arrayData[0].name); //traces name
System.disposeXML(XMLData);
trace(arrayData[0].name); //does not trace, traces nothing
I think George Profenza is correct. Although it way seem a good idea to use an object - unless your parsing out specific information from the XML - using the XML directly and forgoing the use of the object will work just as well. You can traverse and apply the XML in the same way as an object and it'll remove a small overhead.
In accordance to your question, when using XMLData == null
you are clearing the object, but the garbage collector will no touch it until all references to the data are stripped.
using System.disposeXML()
- you're forcing the collection to happen.
Step into the debugger, and stop just as the System.disposeXML()
is called. Watch the object see how its cleaned.
I believe the station.name
is not a string type - and therefore will be referenced back as an object of the XML - Cast is as a string when using it.
This should be done like such:
stationObject.name = String(station.name)
or
stationObject.name = station.name as String
One of these will work.
it will cast the data as a string rather than perhaps an @XML type.