开发者

ActionScript 3 Profiler & Memory Analysis Tool

I'm using Adobe Flash CS 4 and would like to know are there any profiler 开发者_高级运维or memory analysis tools available for it ? (actionscript 3). I know there are available tools for Flex, but are there for Flash CS 4 instead? Thanks.


I'm sure there is a program out there, still looking myself, but I found this on a forum:

Most AS3 beginners have programmed something and then heard about memory leaks. So first I'm going to cover ways to detect and fix leaks in preexisting code, and then talk about preventative measures to take when starting to program.

So how do you know if your program has an issue? The clearest way to tell is if it crashes, but that's very impractical. Fortunately, in AS3 we have an object called System whose properties tell us about the conditions under which Flash is running. System.totalMemory, for instance, is the amount of computer memory being used by the Flash Player instance that's running your program. Different platforms determine the value of System.totalMemory in different ways, so I suggest you only run one Flash player instance at a time when measuring its value.

package {

    import flash.utils.Timer;
    import flash.system.System;

    public class SpitMem {
        var t:Timer = new Timer(0);
        var n:int, lastN:int;

        public function SpitMem():void {
            t.addEventListener("timer", spit2, false, 0, true);
        }

        private function spit1():void {
            trace(System.totalMemory);
        }

        private function spit2():void {
            n = System.totalMemory;
            if (n != lastN)
                trace(n);
            lastN = n;
        }
    }
}

If you create an instance of the SpitMem class above and run your code, you can observe the fluctuations in your program's memory usage in the Output window. This is a lot of information, though, and in this format it cannot give you a clear picture of how your program is using its memory.

(Notice the difference above between spit1() and spit2(). spit2() won't output the System.totalMemory if it hasn't changed. Later I'll show how similar logic can turn our data into something more useful.)

If you make a graph of your data in a spreadsheet program, you'll notice that it always seems to be increasing. That doesn't mean that you have a memory leak. Flash's built-in memory management allows certain types of data to sit around until there is an appropriate time to get rid of it. This is called garbage collection, and for most Flash projects, it will cause your memory to accumulate and then dip down. This is called a sawtooth graph, and it's completely normal.


This is good tool for actionscript 3 memory analysis and profiling http://demonsterdebugger.com/


With the release of the Flash Player 10.1 preview builds, Adobe put out a component that does memory monitoring for you: Memory Monitoring Component

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜