Flash, XML and memory management
October 29, 2003

Since I work with Flash and XML fairly intimately, I'm surprised I didn't notice this before...

If you are using the "Processes" tab of your Task Manager (at least in Windows anyway) to track memory management, you may have come across this too. I was just doing some tests by loading a fairly large xml file (about 600k) locally to see what effect that has on memory used by the Flash player. Just doing a simple:
var sampleXML = new XML();
sampleXML.onLoad = function(success) {
   if (success) {
      trace("done");
    }
}
sampleXML.load("sample.xml");
So I watched the memory usage of the standalone Flash player jump from about 4MB to about 9MB while this happened. No huge surprise...the player parses the XML data into native objects which will result in more memory usage. However, I tried to remove the XML from memory using a button that just runs:
trace("sampleXML before delete:" + sampleXML);
trace("--------------");
delete sampleXML;
trace("sampleXML after delete:" + sampleXML);
When I run this code, everything works as expected:

1) "sampleXML before delete" traces out the XML string.
2) "sampleXML after delete" traces out "undefined".

So far so good.

However, when I go back to check the memory usage, it seems that it's still hovering around 9MB. I do a double take and wonder what's going on. I tried similar tests and all of them seem to result in the same thing...when you delete an XML instance using "delete", it doesn't seem to clear it from memory. I also tried the following ways of clearing it:
// Attempt 1 - replace old instance with new empty instance
sampleXML = new XML();

// Attempt 2 - assign empty string to instance
sampleXML = "";

// Attempt 3 - replace old instance with new instance 
// and load in empty XML file
sampleXML = new XML();
sampleXML.load("empty.xml");
None of these scenarios caused memory to be freed up. So I proceeded to search the usual places...Flashcoders archive, were-here, flashkit. Nothing. Until I stumbled across a post on Flashkit with the following info:

>The memory monitor doesn't necessarily monitor how much memory is currently
>in use by Flash , but rather how much has been *requested.* Flash reserves
>this memory until another process requests it, but >relinquishes it upon
>request. Using the memory monitor may not be giving you >an accurate
>picture.

>Explicitly deleting an object will cause Flash to release >that chunk of
>memory internally for other uses. In the case of >automatic garbage
>collection (such as when a function with local variables >exits) the memory
>is not immediately released - the instance count is >decremented and the
>garbage collection actually deletes the object when there >are enough free
>cycles to do so. This can appear as a "delayed reaction" >as far as memory
>being freed up.

>Macromedia Tech Support

Has anyone else heard of this before? Am I the only one in the dark?

Is there something else I'm missing here? At work, we deal with large amounts of metadata formatted as XML so memory management as we load and unload this data is crucial. Anyone else have anything to add?

Posted by philter at 04:30 PM | Comments Disabled
Is Flash really going to kill Media Players?
October 24, 2003

I just read this link called "Bye Bye Quicktime" at CommunityMX (via JD) and I thought I'd write up a response to it based on my experience.

I currently work as a multimedia consultant for the Learning Technologies Branch (LTB) at Alberta Learning. One of our mandates is to deliver high quality educational "learning objects" to students/parents/teachers for use in and out of the classroom. Being that Flash is one of the most ubiquitous media for providing users with a "rich media" experience, we at LTB and Flash were made for each other. Just about all of our learning objects today involve Flash in some form or another. We have an internal development team of Flash designers/developers working on some of these projects (others are RFP'd out to vendors). So I guess what I'm saying is that we use Flash...extensively.

Now, being that we are producing "multimedia" (is that word antiquated yet?), many of our projects involve media in formats other than Flash. One of the other major formats we use happens to be Quicktime for streaming video.

Obviously, the advances in video in Flash have been great over the years (Flash 5 couldn't really even use video). You can import a video right into the Flash movie, and now, you can even dynamically load video (FLV) at run time for a progressive download. Of course, there is also FlashComm that provides the ability to stream video (again FLV) which is fantastic.

So how is all of this beneficial in what I do at work now? Well, it isn't. Let me explain. I'll choose one example...

One major project we are involved in is in association with National Geographic. It involves delivering video (provided by NG) online through our web portal. The mechanism for navigating through the video listing is a Flash based UI which consumes IMS compliant XML and builds the front end that students see. It's pretty cool stuff. Anyway, all of the video is provided by NG (as Quicktime movies) and our task is to let the users stream this down to their machines and watch it. We also use SMIL records to tag certain bits of the videos so that users can link directly to parts of the videos without having to download them in their entirety. One of the requirements for this project is that the videos are to be displayed in the same window as the Flash UI.

Currently, we are accomplishing this by using a DHTML layer to overlay on top of the Flash movie, so that it looks like the video and Flash movie are seamless. This is ok, and it works in most browsers (except Netscape 4.7 or earlier which just opens in a popup window). However, it requires quite a bit of messy javascript to make it all happen (including OS detects and browser detects galore).

As much as I love Flash, Quicktime is going to be around for a long time, and it's going to be one of the big boys in terms of video. In this instance, we HAD no choice...we had to use the QT plug in to display this video. Now if Flash could stream Quicktime movies, that would be another story...

Now, I don't know all of the implications behind that (what this would do to the player or what ramifications this has on relations between MM and Apple), but it seems to me that it's not a player issue (since after all, you can dynamically load and even stream video through it currently). Is using a proprietary video format a way to try to "squeeze" out the competition? I don't know. Will MM ever open the door for QT movies to be displayed through it? And if they don't, is this a move that will strengthen their market share (ie., more people adopt FlashComm), or is it a move that will deepen the line in the sand between the 2 companies?

This is an issue that is not going to go away for us and we will continue to have to stream Quicktime formatted video to students (generally through Flash UIs)...we have no choice. So as much as I love Flash and think it's the greatest thing since sliced bread, I can't agree that it is going to kill media players (at least not in it's current state). But who knows what the future holds...

Posted by philter at 01:17 PM | Comments Disabled