# \[as3\] Flash Memory Use, THE SEQUEL!

**URL:** <https://forum.kirupa.com/t/as3-flash-memory-use-the-sequel/225118>\
**Category:** flash\
**Created:** [May 8, 2007, 11:23pm UTC](https://forum.kirupa.com/t/as3-flash-memory-use-the-sequel/225118 "2007-05-08T23:23:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rezmason](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rezmason/32/30447_2.png) [@Rezmason](https://forum.kirupa.com/u/Rezmason)\
**Post date:** [May 8, 2007, 11:23pm UTC](https://forum.kirupa.com/t/as3-flash-memory-use-the-sequel/225118/1 "2007-05-08T23:23:13Z")

</div>

Hi again! I’m back, this time with some _graphs_!

A short while ago I started a thread on Flash’s memory usage, and how to track down memory leaks. Toward the end of the thread, I posted a link to ActiveGraph, a class I made that helps you keep track of what _should be_ the active memory in use by the Flash Player. (Quick recap- active memory is the memory Flash is actually using; when memory is no longer active, it is called _garbage_, and doesn’t go away until the memory limit imposed by Flash or the OS is reached, and the “garbage collector” is run.) You can read about all that and download ActiveGraph [here](http://kirupa.com/forum/showthread.php?t=258129).

Since then, I’ve been using ActiveGraph to track down memory leaks in my latest project, BitmapEditor. (Eventually I’ll open-source it, but first I’ve got to eradicate potential leaks.)

To just quickly restate how ActiveGraph decides what’s active memory and what’s not, the code in ActiveGraph looks at System.totalMemory (active memory + garbage) every 100 ms or so, and if the totalMemory ever goes down, ActiveGraph assumes that the garbage collector is responsible. That means, at that moment in time, there should be no garbage, so totalMemory should equal active memory. So ActiveGraph only outputs data when there’s been a totalMemory decrease.

If you graph totalMemory plain and simple, you should get a “sawtoothed” graph- it steadily increases, but every now and then (when the GC runs), it sharply goes down. ActiveGraph “overlooks” these sawtooths, drawing a line _beneath_ the teeth (which are made of accumulating garbage). So, if ActiveGraph really is outputting active memory, then the graph it makes should be stable- wavering up and down a little, without “sawtoothing”.

Are we all on the same page? Cool.

Now, take a look at these two graphs. Their data came from looking at the same program- BitmapEditor- through ActiveGraph, but during one of them, I had commented out the code that draws some animated content. When I left it uncommented, _the graph still sawtooths_, but slower. When I comment it out, the graph stays relatively stable (or so it seems).

[Graph 1.](http://www.rezmason.net/other_files/forum_resources/graphs/be1.png)  
[Graph 2.](http://www.rezmason.net/other_files/forum_resources/graphs/be2.png)

I decided to see if this happened outside of my project, and I created a simple Flash file called Barebones3, which contains ActiveGraph and does nothing; it just has a bunch of instances of a movieclip on the stage. You can see some of those graphs here:

[Graph A.](http://www.rezmason.net/other_files/forum_resources/graphs/b3a.png)  
[Graph B.](http://www.rezmason.net/other_files/forum_resources/graphs/b3b.png)  
[Graph C.](http://www.rezmason.net/other_files/forum_resources/graphs/b3c.png)  
[Graph D.](http://www.rezmason.net/other_files/forum_resources/graphs/b3d.png)

I tried to switch things up, to see whether the graph changes at all if, say, bitmap caching is turned off or something. But there’s no change- _all the animated content I’ve seen so far causes a sawtoothed graph._ And a sawtoothed graph means, there’s still garbage.

Remember, these graphs are supposed to be garbage-free! I think what’s happening is, data for animated content gets handled by a different garbage collector than other data. The sawtooth graphs we’re seeing here are caused by a second, slower GC. Or, there could be one GC event that deals with _reference counting_, and a slower one for _mark and sweep_- two garbage collecting strategies that, optimally, happen at different times from one another.

But that’s speculation, and it’s not as important as the implications of this: your program may be slowed down by your animation, or by something else, and in order to test your program for memory leaks, it’s wise to have in place a system that’ll replace all your timeline animations- especially the ones that use filters and such- with placeholders, at least until you’re done debugging.

Frankly, I think I’m coming close to over-thinking this, and I doubt it’s that important to you all. As long as you keep your programs kind of slim, you’ll probably never even notice these things. But seeing this sawtooth pattern in the graphs, after already compensating for another sawtooth pattern, is a big surprise.

Finally, does anybody know someone from Adobe who I can talk to about this, who’s generally open to questions? If anyone here’s had success talking to a bigwig like Grant Skinner, Mike Downey, Mike Chambers, or just _somebody_ who could give these graphs some more meaning, I’d like to know who that was. 🙂

And now I’ll open the floor to questions.
