Skip navigation
bbitmmstr
Currently Being Moderated

Memory leak using URLStream

Feb 12, 2013 12:18 PM

Tags: #actionscript #memory_leak #air3 #urlstream

I have an Air application that needs to loop through thousands of URLs to download and save images to the user's local drive.  I am able to get through a few hundred but receive the following error:

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.

 

Others have mentioned that this error means that the URL doesn't exist or is invalid but I can guarantee that the URLs are valid.

 

Here is how my class is getting called:

    var fp:FileProcessor = new FileProcessor(imgPath, dirPath);

    fp.addEventListener(Event.COMPLETE, imgDownloadComplete);

    fp.startDownload();

 

And in imgDownloadComplete, after updating the progress bar I am calling:

 

  var fp:FileProcessor = event.currentTarget as FileProcessor;

  fp.removeEventListener(Event.COMPLETE, imgDownloadComplete);

  fp = null;

 

Finally, FileProcessor looks like:

public class FileProcessor extends EventDispatcher {

                    private var urlPath:String;

                    private var dirPath:String;

                    private var urlStream:URLStream;

                    private var fData:ByteArray;

                    private var file:File;

 

                    public function FileProcessor(url:String, path:String) {

                              this.urlPath = url;

                              this.dirPath = path;

             //////This next line is where the error above points to

             urlStream = new URLStream;

             urlStream.addEventListener(ProgressEvent.PROGRESS, onProgress);

             urlStream.addEventListener(Event.COMPLETE, onComplete);

                    }

 

                    public function startDownload():void {

                              fData = new ByteArray;

                              urlStream.load( new URLRequest(this.urlPath) );

                    }

 

                    private function onProgress(event:ProgressEvent):void {

                              if(urlStream.bytesAvailable == 0) return;

                              if(urlStream.connected) urlStream.readBytes(fData, fData.length);

                    }

 

                    private function onComplete(event:Event):void {

                              if(urlStream.connected)

                                        urlStream.close();

 

                              var fileStream:FileStream = new FileStream;

                              file = File.desktopDirectory.resolvePath(this.dirPath);

                              fileStream.open(file, file.exists ? FileMode.APPEND:FileMode.WRITE);

                              fileStream.writeBytes(fData);

                              fileStream.close();

 

                              fData.clear();

                              fData = null;

                              file = null;

                              fileStream = null;

 

                              urlStream.removeEventListener(ProgressEvent.PROGRESS, onProgress);

                              urlStream.removeEventListener(Event.COMPLETE, onComplete);

 

                              urlStream = null;

                              dispatchEvent(new Event(Event.COMPLETE));

                    }   

 

                    private function dispatchComplete():void {

                              dispatchEvent(new Event(Event.COMPLETE));

                    }

          }

}

 

ANY help or pointers that somebody can give would be greatly appreciated.  This is my first shot at an Air/Flex application so I am unsure where to look.  My company wouldn't purchase the Professional FlexBuilder so I do not have access to the profiler.

 
Replies
  • Currently Being Moderated
    Feb 12, 2013 3:21 PM   in reply to bbitmmstr

    Look at the app in the process manager and see if memory is climbing significantly at the time of faiure.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 3:33 PM   in reply to bbitmmstr

    On Windows, hit ctrl-alt-delete and choose Task Manager.

    On Mac, run Utilities/ActivityMonitor.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 8:30 PM   in reply to bbitmmstr

    The application stops or starts getting ioerrors or something else?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points