TIPS & TRICKS

Flash/AS3 URLStream Memory Leak

Lately we have been doing some work with persistent connections. If you are familiar with Comet the Flash/AS3 URLStream class provides an interesting alternative. The URLStream class exposes raw binary data as it is downloaded.

Unfortunately, this week we ran into a rather tricky memory leak when using this nifty class. An event listener was subscribed to the progress event and over time memory usage steadily increased to a point of making the browser inoperable.

After a little digging we narrowed the problem down to the URLStreams usage of the ByteArray. It seems as if URLStream was reallocating a buffer for the array and the short turn around time (on the reads) was not giving the garbage collector enough time to throw out the old allocation.

The way the leak could be corrected was by deleting the ByteArray (Set null), forcing garbage collection of the read buffer.

Here is the workaround:


var bytes:ByteArray = new ByteArray();
this.readBytes(bytes, 0, this.bytesAvailable);
bytes = null;

Happy Streams!

Carl has always had a passion for problem solving through visualization rding. He has designed and implemented data analytics solutions using Splunk as a platform spanning almost every industry. Now, as part of the technical product marketing team, I get to bring our product to life. My goal is to make big data analytics simple and usable to anyone for anything.

He has designed and implemented data analytics solutions using Splunk as a platform spanning almost every industry. Now, as part of the technical product marketing team, I get to bring our product to life. My goal is to make big data analytics simple and usable to anyone for anything.

Join the Discussion