FileReference.load
does not have a function to unload, as there is new Loader().unload
.
Should be a Flash BUG or FileReference needs to be improved, type in a new version to add a function like this: FileReference.unload();
Or am I wrong and is there a SOLUTION?
I tried to set NULL
to a variable of type :FileReference
, but clearly this does not work because Flash works with GC (garbage collector), but this is not the focus of the question.
The problem is that loading multiple files with FileReferenceList
requires a lot of memory, but I can not free up memory after the process.
How to free memory after using FileRerence
?
My code:
Main.as
package {
import com.mainpackage.LoaderTestCase;
import flash.net.FileReferenceList;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.Event;
import flash.display.MovieClip;
public class Main extends MovieClip {
private var listFiles:Array;
private var allTypes:Array;
private var fileRef:FileReferenceList;
private var test:int;
public function Main()
{
test = 0;
listFiles = [];
allTypes = [];
fileRef = new FileReferenceList();
fileRef.addEventListener(Event.SELECT, select);
fileRef.browse(allTypes);
}
private function select(e:Event):void
{
listFiles = fileRef.fileList;
for(var i:uint=0, j:uint=listFiles.length; i<j; i++)
{
insert(i);
}
}
private function insert(c:int):void
{
var fire:LoaderTestCase = new LoaderTestCase(listFiles[c]);
fire.destroy(function():void
{
//Delete LoaderTestCase after timeout ???
fire = null;
test++;
if(test>=listFiles.length) {//Remove FileReference
fileRef.removeEventListener(Event.SELECT, select);
fileRef = null;
for(var i:uint=0, j:uint=listFiles.length; i<j; i++) {
listFiles[i] = null;
}
listFiles = null;
trace("Clear memory");
}
});
}
}
}
LoaderTestCase.as
package com.mainpackage
{
import flash.net.FileReference;
import flash.events.Event;
import flash.display.Loader;
public class LoaderTestCase
{
private var file:FileReference;
private var loader:Loader;
private var callback:Function;
public function LoaderTestCase(e:FileReference)
{
file = e;
trace("OPEN: " + file.name);
file.addEventListener(Event.COMPLETE, loadFile);
file.load();
e = null;
}
public function loadFile(e:Event):void
{
file.removeEventListener(Event.COMPLETE, loadFile);
trace("LOAD: " + file.name);
file = null;
e = null;
callback();
}
public function destroy(a:Function):void
{
callback = a;
}
}
}