You can use a variety of techniques to identify problem areas in your applications by using the profiler.
One of the most common problems you face in application development is memory leaks. Memory leaks often take the form of objects that were created within a period of time but not garbage collected. By comparing two memory snapshots in the Loitering Objects view, you can determine which objects are still in memory after a particular series of events.
Loitering Objects view shows you potential memory leaks. The Instances and Memory columns show the differences between the number of instances of a class and the amount of memory consumed by those instances during the interval between one snapshot and the next. If you see a class that you did not expect to be created during that time, or a class that you expected to be destroyed during that time, investigate your application to see if it is the source of a memory leak.
One approach to identifying a memory leak is to first find a discrete set of steps that you can do over and over again with your application, where memory usage continues to grow. It is important to do that set of steps at least once in your application before taking the initial memory snapshot so that any cached objects or other instances are included in that snapshot.
Then you perform that set of steps in your application a particular number of times -- 3, 7, or some other prime number -- and take the second memory snapshot to compare with the initial snapshot. In the Find Loitering Objects view, you might find loitering objects that have a multiple of 3 or 7 instances. Those objects are probably leaked objects. You double-click the classes to see the stack traces for each of the instances.
Another approach is to repeat the sequence of steps over a long period of time and wait until the memory usage reaches a maximum. If it does not increase after that, there is no memory leak for that set of steps.
Common sources of memory leaks include lingering event listeners. You can use the removeEventListener() method to remove event listeners that are no longer used. For more information, see Object creation and destruction in Building and Deploying Adobe Flex 3 Applications.
By analyzing the execution times of methods and the amount of memory allocated during those method calls, you can determine where performance bottlenecks occur.
This is especially useful if you can identify the execution time of methods that are called many times, rather than methods that are rarely called.
Determine frequency of method calls
The value in the Calls column is the number of times that method was called during this sampling interval. This is the time between when you clicked the Reset Performance Data button and when you clicked the Capture Performance Profile button.
Examine the values in the Cumulative Time, Self Time, Avg. Cumulative Time, and Avg. Self Time columns of the Performance Profile view. These show you the execution time of the methods.
Compare the time each method takes to execute against the time that all the methods that are called by a particular method take to execute. In general, if a method's self-time or average self-time are high, or high compared to other methods, you should look more closely at how the method is implemented and try to reduce the execution time.
Similarly, if a method's self-time or average self-time are low, but the cumulative time or average cumulative time are high, look at the methods that this method calls to find the bottlenecks.
One way to identify trouble areas in an application is to find out where you might be creating an excessive number of objects. Creating an instance of an object can be an expensive operation, especially if that object is in the display list. Adding an object to the display list can result in many calls to style and layout methods, which can slow down an application. In some cases, you can refactor your code to reduce the number of objects created.
After you determine whether there are objects that are being created unnecessarily, decide whether it is reasonable or worthwhile to reduce the number of instances of that class. For example, you could find out how large the objects are, because larger objects generally have the greatest potential to be optimized.
To find out which objects are being created in large numbers, you compare memory snapshots of the application at two points in time.
View the number of instances of a specific class
For more information about the Memory Snapshot view, see Using the Memory Snapshot view.
Locate instances of excessive object allocation
The profiler saves the memory snapshot in the Profile view, and marks the snapshot with a timestamp.
The profiler saves the second memory snapshot in the Profile view, and marks the snapshot with a timestamp.