Skip to main content
Known Participant
October 29, 2015
Question

Downloading and saving a zip file is giving out of memory error

  • October 29, 2015
  • 1 reply
  • 416 views

Hi,

I am downloading a 408.9 MB zip file through URLStream class. Below is my code.

protected function window1_creationCompleteHandler(event:FlexEvent):void

  {

  var urlStream:URLStream = new URLStream();

  var urlReq:URLRequest = new URLRequest(downloadUrl);

  urlStream.addEventListener(ProgressEvent.PROGRESS, handleProgress);

  urlStream.addEventListener(Event.COMPLETE, handleDownloadComplete);

  urlStream.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);

  urlStream.load(urlReq);

  }

  private function handleProgress(event:ProgressEvent):void

  {

  progressBar.setProgress(event.bytesLoaded, event.bytesTotal);

  progressBar.label = "Downloading [" + Math.round(event.bytesLoaded / event.bytesTotal * 100).toString() + "%]";

  }

  private var totalFile:uint;

  private var currFile:uint;

  private var fileList:Array;

  private var albummStorageFile:File;

  private var albumZipFile:File;

  private function handleDownloadComplete(event:Event):void

  {

  var stream:URLStream = event.currentTarget as URLStream;

  var data:ByteArray = new ByteArray();

  stream.readBytes(data,0,stream.bytesAvailable);

  albumZipFile = File.applicationStorageDirectory.resolvePath("seldex_album.zip");

  var fileStream:FileStream = new FileStream();

  fileStream.open(albumZipFile, FileMode.WRITE);

  fileStream.writeBytes(data,0,data.length);

  fileStream.close();

  }

This line is giving error: Error #1000: The system is out of memory.

  stream.readBytes(data,0,stream.bytesAvailable);


stream.bytesAvailable valus is 408975369 at runtime.


I don't know what's causing the error.


Please help.


Thanks in advance.

This topic has been closed for replies.

1 reply

October 29, 2015

How much RAM does the computer you are working with have? Could try tracing out "System.totalMemory" right before the line that is giving the error and see how much memory it says your app is using right before that point. There is also "System.freeMemory" which reports, in bytes, how much free RAM is available to the AIR app. Found a post on StackOverflow of a person saying that AIR can use about 1GB of memory. No idea what his credentials are to give credence to that statement, but something to think about in case there is validity to it.