Jump to content
Search Community

LoaderMax seems to be holding onto ByteArrays and NetworkBuffer

crooksy88 test
Moderator Tag

Recommended Posts

I'm using LoaderMax to load several .flv files.

_queue = new LoaderMax({name:"mainQueue", onComplete:finishedDownload, maxconnections:2});

for (i = 0; i < _numFiles; i++) {
_queue.append( new DataLoader(_filesToDownload[i][0], {name:_filesToDownload[i][0], format:"binary", estimatedBytes:_filesToDownload[i][1]}) );
}

_queue.load();

When the queue has completed it calls:

private function finishedDownload(event:LoaderEvent):void {
_queue.dispose(true);
_queue.unload();
_queue = null;
}

I then repeat the loading sequence again with a new set of flv urls. As I watch this in Scout though, despite calling dispose and unload on the queue, I see a gradual increase in ByteArrays and Network Buffers until the app crashes, presumably running out of memory.

 

I've attached a screenshot of the Scout display.

 

I have no other ByteArray allocations going on so this seems to be linked to LoaderMax.

 

Would anyone have an idea on how I can clear these ByteArrays and Network Buffers?

 

Thanks,

 

Mark

 

 

 

post-9402-0-06700300-1371894633_thumb.png

Link to comment
Share on other sites

I don't see any obvious problems, no. Feel free to check the source code of DataLoader and you'll see that if you dispose(true), it closes the URLLoader, nulls the content reference internally, and dumps any internal references to that entire DataLoader instance, freeing it for GC. If you notice anything strange in the GreenSock code, let us know. But I'm pretty sure it's not the cause of the memory leak. 

Link to comment
Share on other sites

Thanks Jack,

 

I don't know if you're interested in investigating this further but this issue does seem to be linked with using GSAP.

 

I've altered my code to use a regular URLStream and according to Scout, the ByteArrays are not held onto and the Network buffer is now being purged by Garbage Collection.

 

I've included my code in case it's of interest to anyone as well as a Scout screenshot showing the network buffer purge.

 

This was running on Air 3.7 for Android (on a HTC One).

 

 
var _downloadItemIndex:int = 0;

private function downloadAFile():void {

_downloadItemName = _filesToDownload[_downloadItemIndex];

_urlString =  ANDROID_DOWNLOADS_URL + _downloadItemName;
_urlReq = new URLRequest(_urlString);
_urlStream = new URLStream();

_urlStream.addEventListener(flash.events.Event.COMPLETE, saveFileToDisc, false, 0, true);
_urlStream.load(_urlReq);

}


private function saveFileToDisc(event:flash.events.Event):void {

_dataD = new ByteArray();

_urlStream.readBytes(_dataD, 0, _urlStream.bytesAvailable);

_dFile = File.documentsDirectory.resolvePath("Includes/"+ _downloadItemName);
_fileStream = new FileStream();
_fileStream.addEventListener(flash.events.Event.CLOSE, fileSaved, false, 0, true); 
_fileStream.openAsync(_dFile, FileMode.UPDATE); 
_fileStream.writeBytes(_dataD, 0, _dataD.length); 
_fileStream.close();
_dataD.length = 0;
_dataD = null;
            
}


private function fileSaved(closeEvent:flash.events.Event):void {
_downloadItemIndex++;
if (_downloadItemIndex < _numFiles) {
downloadAFile();

} else {

_fileStream.removeEventListener(flash.events.Event.CLOSE, fileSaved);
_urlString = null;
_urlReq = null;
_urlStream = null;
_dFile = null;
_filesToDownload = [];
_filesToDownload = null;
_dataD = null;
_fileStream = null;

trace("finished");
}
                    
}
 

post-9402-0-22433500-1372077706_thumb.png

Link to comment
Share on other sites

Have you tried using a URLLoader? I wonder if Adobe has an issue with their URLLoader or something (that's what DataLoader must use).

 

Feel free to extend DataLoader or LoaderItem to create your own that's based on URLStream instead. That way, it'd fit into the LoaderMax ecosystem nicely.  

Link to comment
Share on other sites

  • 5 months later...

Without a simplified FLA demo that clearly shows the issue, I'm afraid I'm just not able to diagnose it. I can say that nobody else has reported anything like this in the past (that I can remember at least), and I cannot imagine how LoaderMax would specifically be causing the problem (I suspect it could have something to do with Adobe's URLLoader, but again, it's very tough to troubleshoot blind and a small excerpt of code isn't sufficient).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...