[f9 AS3] Understanding System.totalMemory

Hello!

For a long time I’ve been puzzled by the new System.totalMemory variable. Whenever I make an AS3 project, I try using the following code:

package whatever {
	import flash.system.System;

	public class Example extends Sprite {
	private var mem:int=0;
	private var n:Number;
	.
	.
	.

	private function checkMem():void {
		n = System.totalMemory;
		if (mem != n) {
			trace( n, (n-mem)/4096 ); 
			mem = n;
		}
	}
}

So the checkMem function outputs the number of 4-kilobyte chunks of memory allocated or deallocated since the last call to checkMem. And more often than not, calling this function at regular intervals will reveal something like this:

9273344 2264
9269248 -1
9527296 63
9535488 2
9547776 3
9551872 1
9576448 6
9633792 14
9662464 7
9711616 12
9715712 1
9723904 2
9719808 -1
9728000 2
9723904 -1
9719808 -1
9723904 1
9728000 1
9740288 3
9736192 -1
9732096 -1
9736192 1
9732096 -1
9736192 1
9732096 -1
9736192 1
9740288 1
9736192 -1
9748480 3
9752576 1
9756672 1
9752576 -1
9768960 4
9764864 -1
9768960 1
9773056 1
9793536 5
9797632 1
9801728 1
9805824 1
9809920 1
9814016 1
9842688 7
9895936 13

(The above output is from four or five seconds of one running AS3 project.)

This raises several questions. Does Flash always allocate memory in 4K chunks? And how can I diagnose this leak? I mean, using the Example class above as the document class, and leaving as it is written above, will still result in a memory leak!

So far I’ve read the gskinner blog entries on memory management, and they really can only do so much good- they say nothing about how to find a leak. Does anyone have any advice?