Digital Media WebWeb > Features

Flex 3 Cookbook: Chapter 21, Compiling and Debugging

Flex 3 Cookbook: Chapter 21, Compiling and Debugging
Pages: 1, 2, 3, 4

Section 21.13: Use Memory Profiling with Flex Builder 3 to View Memory Snapshots

Problem

You want to view all the objects allocated in the Flash Player’s memory at runtime.

Solution

Use the Memory Profiler view in Flex Builder 3 to run your application and observe the objects being created and destroyed.

Discussion

The Flex Profiler is a new addition to Flex Builder 3 and is a powerful tool that enables you to watch an application as it allocates and clears memory and objects. It connects to your application with a local socket connection. You might have to disable antivirus software to use it, however, if your antivirus software prevents socket communication.

As the Profiler runs, it takes a snapshot of data every few milliseconds and records the state of the Flash Player at that snapshot, a process referred to as sampling. By parsing the data from sampling, the Profiler can show every operation in your application. The Profiler records the execution time of those operations, as well as the total memory usage of objects in the Flash Player at the time of the snapshot. When an application is run in the Profiler, you’ll see the Connection Established dialog box (). Here you can enable memory profiling to help identify areas of an application where memory allocation problems are occurring, as well as enable performance profiling to help improve the performance of an application.

Example
Figure 21-6: Selecting a profiling type

If you turn on the Watch Live Memory Data check box, the Profiling view displays live graphs of the objects allocated in the Flash Player ()

Example
Figure 21-7: Live object and memory allocation data in the Flex Profiling view

This excerpt is from Flex 3 Cookbook. This highly practical book contains more than 300 proven recipes for developing interactive Rich Internet Applications and Web 2.0 sites. You'll find everything from Flex basics and working with menus and controls, to methods for compiling, deploying, and configuring Flex applications. Each recipe features a discussion of how and why it works, and many of them offer sample code that you can put to use immediately.

buy button

The Profiler provides memory snapshots that can be taken at any time and provide in-depth data about the number of instances of any object and the amount of memory that they require (Figure 21-8).

Example
Figure 21-8: Viewing the number of instances and memory consumption in a memory snapshot

Finally, you can compare any two memory snapshots from different times in the application to find loitering objects, that is, objects that were created after the first memory snapshot and exist in the second. Information about the class name, memory size, and number of instances are all included in the Loitering Objects view ()

Example
Figure 21-9: Viewing all generated objects in the Loitering Objects screen

Skip to any available Digital Media Help Center chapter of Flex 3 Cookbook:
Chapter 8 | Chapter 20 | Chapter 21

Joshua Noble is a consultant, freelance developer and Rich Internet Application designer, based out of Brooklyn, who most recently worked at the popular RIA design/dev firm Schematic, Inc.

Todd Anderson is a Senior Software Developer in the Multimedia Platforms Group at Schematic Boston, and is co-author of Adobe AIR Instant Results: Create - Modify - Reuse, a Wrox/Wiley title scheduled for release in spring of 2008.