Wednesday, February 28, 2007

Severe memory issues in flash with JPG sequences

So when doing a new (first) project for Heineken (for my company QI) we run in a big issue with flash and the carbage collector. It seems when you have a JPG sequence on stage the JPG's stays in memory even when attached and removed out of the library. We used a jpeg sequence instead of fullscreen video because JPEG tends to have smoother playback for our 3D animations.

But think 100 jpeg images of 1014 x 690 resolution. Flash needs 3MB to show one frame. So after about 100 jpeg's flash needed 300MB virtual memory, this memory never got freed by the carbage collector .. So the slower computer with not that much RAM would suffocate.

After doing some tests, it seems when loading an external SWF in a mc (with a linked sequence in library). And after loading, attaching the linked sequence in that mc. The MC can be removed and memory gets freed.

For now we have cutted the sequence in different parts, so after playing a part it can unloaded.

  • We have for example 3 sequences in library in a single SWF called sequence.swf.
  • we create 3 container MC's where we load in the same SWF (cache :>)
  • we start the seqeunce and attach in container1 > sequence1 after playing the first sequence we remove container1 and attach sequence2 in container 2.
  • and so on..

This heavely relies on cache and is a not so nice solution so ANYONE got a better one I would love to hear it.

NYLS

5 comments:

Anonymous said...

Lower your frame rate of your sequnce to 15 fps. Must you use a swf with all the jpegs in the lib?

Can you load them in dynamically into bitmap data objects and cache those and cycle through those with bitmapdata cache on.

If you only need to show it once, you can dispose of each frame by calling bitmapDataObj.dispose() after each frame.

You can get good quality out of FLV's if you tinker around with squeeze in the advanced settings, you get the best quality FLV for your kb's. All other FLV compression packages arent as good as Sorenson's.

Niels de Keizer said...

Lowering framerate is not an option, the main site uses a framerate of 25, so we are stuck with that.

I have tried linking the jpg's in the library's and loading them in BitmapData objects. This works but

var bmpName = nameArray.shift();
bmp.dispose();
bmp = BitmapData.loadBitmap(bmpName);
this.attachBitmap(bmp,this.getNextHighestDepth());

the loadBitmap takes to long so playback is also not smooth.

We work a lot with sorenson and on2Flix (we like the last better) but could not get the same smooth results as a jpeg sequence.

The problem here is that flash does not release the jpg's out of memory.

Anonymous said...

Hi
did you find a solution ? I wasted a long day to find a solution ... nothing
please contact me pjl [to] kama3d .org

Anonymous said...

Hej Nyls,

Sure you not keeping any reference to the containing mc of the jpg or something ? This is sounding weird to me for now. Otherwise just loadBitmap would be your best option. You could check on garbage collection by forcing it in Flash 9 :

try {
new LocalConnection().connect('foo');
new LocalConnection().connect('foo');
} catch (e:*) {}

That's not document, not supported, and very hacky though...might not even work; but it might give you a hint as to where things are stuck.

Anonymous said...

This sounds like an issue I'm having on a game I'm making. The jpeg sequence is the ruff animation for what is going to be cleaned up into Disney style animation. I'm hoping that once I make vector images of the character and delete the jpegs it will slow down. Any ideas?