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.
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).
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.
Graph B.
Graph C.
Graph D.
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.