flex memory leak problem

Flex memory leaks

Transfer from: http://blog.csdn.net/lena_20081215/archive/2009/01/08/3735708.aspx

Article 2
FLEX memory optimization techniques collection type: reproduced
FLEX memory optimization principles released
1. Is deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of;
2. Parent child objects within other objects by an external reference, and will lead to the child object is not deleted, the child object will not be removed will result in the parent will not be deleted;
3. If an object reference to an external object, as they have been deleted or does not need to use this reference object, we must remember that a reference to this object is set to null;
4. The object can not remove the causes are not necessarily that they have been cited, there may be an external reference to their own children, and children can not afford to lead delete delete stubborn father;
5. In addition to references to delete, the system components or whole instruments, management provides the uninstall method if there must be invoked to delete internal objects, or they may result in loss of memory leaks and performance;
6. The parent object is deleted immediately does not mean that the child object will be immediately removed or deleted, the system may later be automatically deleted or second removal operation is deleted;
7. If the parent remove the child object does not have any clear reference to the object pairs, as the child object can not be deleted, the parent object and can not be deleted;
8. Registration of events if not removed from the definition of force does not affect the recovery mechanism, but may affect the normal recovery mechanisms, so it is best to do an event listener registration should remember to remove cleaner.
9. The parent object is deleted does not mean the rest of sub-objects are removed, the disclosure of code to find a state does not mean that other states would not leak, and to the status of each module were tested one by one until the test can be removed under any until the entire object.

Memory leak example:
1. Reference leak: pair object reference, an external object or child object to this reference have to set null;
2. System classes leaks: Use a system class and forget to do the delete operation, and as BindingUtils.bindSetter (), ChangeWatcher.watch () function when finished you need to call ChangeWatcher.unwatch () function to clear the reference, or use this function the object will not be deleted;
There are similar MUSIC, VIDEO, IMAGE, TIMER, EVENT, BINDING so.
3. Effects disclosure: When the Application Effect on components of the time, when the object when the deleted object and child objects to the Effect on the animation stops away, Effect of target objects and then set null; If you do not stop directly out animation Effect null set will not function properly remove the object.
4. SWF disclosure: To completely remove a SWF to call it the unload () method and the target set null;
5. Pictures leak: When Image object source after use should be set null; (for testing);
6. Voice, video leak: When do not need a music or video is the need to stop the music, delete the object, reference set null;
Memory leak solution:
1. REMOVED_FROM_STAGE event back in the components to do away waste operations (removal of all external references (whether VO or components need to remove), remove the listener, calling the removal method of system classes)
First remove and then set null, remove or removeAll ensure that the object after the release of all external references to a clean;
2. Use Flex Profile to the performance of optimization tools to monitor progress on the project, know history, which objects to create Guo, there are objects which have not been removed, to create the number and proportion of the memory usage, and other information to create Guo Cheng;

Summary: The key is to make clear the work, their own set of reference they have to remember to delete their own system of categories used to remember the good recycling work. Above do not solve the problem well, it would force the collector custom may also be automatically recovered by the system out of normal.

Article 2

Performance for Flex I think a lot of people who really intend to use it the most concern, is also used for so long I understand the issue more deeply,
The current performance I have ever done is a big problem, where I summarized some of the technical performance of the method.

1. To avoid deeply nested containers (because of its sub-containers for each container will be calculated and adjusted, generally recommended HBox, VBox is best not more than three layers, but this is difficult to avoid the complex system)
2. For containers and space, location and size of the absolute coordinate and maximize the use of hard-coded. (Less Flash Player nested depth calculation)
3. Reasonable and appropriate use of Grid container, ordinary containers can be used as for the HBox, VBox to achieve as much as possible not to use Grid (Grid nesting levels deep)
4. To avoid duplication, redundant nested containers, such as:
1) Panel, Application to add a layer of VBox, Panel, Application originally inherited from VBox, and add unnecessary VBox can lower your system's performance.
2) For custom containers to reduce unnecessary duplication of the parent container, such as:
<mx:VBox backgroundColor=" #FFCCCC" borderStyle=" solid">
<myComponent xmlns=" *" />
</ Mx: VBox>
You can use the following wording, which itself is likely to myComponents VBox
<myComponent xmlns=" *" backgroundColor=" #FFCCCC" borderStyle="solid" />
5. Latency navigation class to instantiate containers (Deferred Instantiation Navigator Containers)
If ViewStack, Accordion, TabNavigator so, in itself provides a delay function is instantiated, you only need to modify their creationPolicy = 'auto' can be, it will only instantiated the first to show the child controls, and the rest will be needed when instantiated.
6. For the flex effect (Effects) to be as smooth as possible (Smoothly), such as extension of its duration (duration), avoid the use of bmp format image as background.
7. For the DataGrid complex ItemRenderer, try to use the Canvas instead of VBox or HBox, and Flex 1.5 this is different.
8. If the DataGrid's ItemRenderer a ComboBox, so as not to use ItemEditor ItemRenderer, only elected in the cell will display the Renderer (to avoid a one-time all the cell Renderer are drawn)
9. I remember at any time Listener Remove useless or use weak references, this mechanism in the event I mentioned (URL. ..); null unused variables and arrays.
10. For the use of large quantities of data when necessary to fetch or page
11. Advance statement frequently used variables, such as:
var l: int = list.length;
var w: int = stage.stageWidth;
for (var i: int = 0; i <l; i + +) (
list [i]. x = w -100;
)
12. This can improve the performance of Flex, probably many people will not bother, but at least it can reduce unnecessary for Flex in terms of computing to improve performance, I think this program really a matter of habit is not easy to change, at least I was 1 year or until recently aware of this issue.
In addition the proposals and code organizations, such as:
1) systematic constant write a constant with the const keyword class inside and some ItemRenderer code to be independent and not directly into a document written everywhere
2) Do not quote long list of elements in the interface of parent.parent.parent ..., once the interface re-organization will give you great trouble. If you use the Cairngorm framework, then it should ViewHelper, your code is loosely coupled as possible.
13. Modify the production-mode attribute is true, 2.01 in the file in the flex-webtier-config.xml. It generally is the product release time to set, you can be understood as c + + in Release and Debug versions of differences.
14. If you use FDS, then try to use the Remote Object and not Http Service or Web Service, because the former is the most efficient
15. On stress testing your system, Adobe has a testing tool, called the Flex Stress Testing Framework
(Rul: http://labs.adobe.com/wiki/index.php/Flex_Stress_Testing_Framework).
It provides RPC in the RTMP, AMF, HTTP test, general commercial testing software does not support the first two tests,
The software is free, you can go to Adobe official website, the next (URL: http://download.macromedia.com/pub/labs/flexstress/flex_stressfw_p2_060407.zip)

分类:Flash 时间:2010-07-12 人气:246
分享到:
blog comments powered by Disqus

相关文章

  • JVM garbage collection summary (8): Reflection and Reference 2010-08-26

    The Paradox of garbage collection The so-called "winner Xiao He Xiao He lost." Java's garbage collection have brought many benefits for the development is made easier. However, in some high-performance, high concurrency situation, garbage collec

  • Flex garbage collection and performance optimization of a number of summary 2010-08-28

    Some knowledge of Flex garbage collection summary: 1, deleted all references to objects in the external must be removed as a clean garbage collection system can be disposed of. 2, the child within the parent object is an external reference other obje

  • Java's garbage collection summary and to learn Java garbage collection mechanism for experience 2008-06-09

    Memory is a scarce resource, even if memory, a money one! If the improper use of programming, then the memory will run out of big. First, understand Java's automatic garbage collection garbage collection is one of the major characteristics of Java la

  • . Net memory management and garbage collection 2010-04-20

    . NET Framework's garbage collector management application memory allocation and release of. Every time you use the new operator to create an object, the runtime objects are allocated from the managed heap memory. Managed heap as long as the address

  • Popular various garbage collection algorithm to explain 2010-04-20

    Reference count (Reference Counting) Method Before 1960, it was the embryo of the Lisp language design garbage collection mechanism, the first thought of the algorithm is the reference counting algorithm. Take the case of napkins, the principle of th

  • Various garbage collection algorithms popular explanation (change) 2010-04-28

    Reference count (Reference Counting) Method Before 1960, it was the embryo of the Lisp language design garbage collection mechanism, the first thought of the algorithm is the reference counting algorithm. Take the case of napkins, the principle of th

  • JavaScript garbage collection 2010-06-05

    If you can not afford to use nested functions will not release the memory recall function of memory, I can assure normal circumstances, javascript does not recall any memory that is running the script for the release of the launch or re-initialize on

  • [Original] Flash's garbage collection and memory leak 2011-05-27

    ActionScript3.0 garbage collector positioning using two methods without reference to the object reference count and identify the clear method. Reference counting, an object used to track the activities of a relatively simple method, which started fro

  • Java, garbage collection and object life cycle 2010-06-21

    In "<Java Programming ideas >> book, the author outlines the essence of garbage collection:" Adaptive based platform stop - copy "garbage collection technology and" sun of early adaptive mark - sweep "garbage collection t

  • java garbage collection 2008-11-29

    We know that many programming languages are allowed in the program run-time dynamically allocated memory space. A variety of ways to allocate memory, depending on the grammatical structure of that language. But no matter what kind of language, memory

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.358 (s). 14 q(s)