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;
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)
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of flex memory leak problem

  • Javascript in the browser environment (seven) XMLHttpRequest

    XMLHttpRequest XMLHttpRequest is a function used to create a http request. XHR initial IE through ActiveX objects are realized. After the beginning of the various browsers support. Now AJAX is the popular XMLHttpRequest object to the adoption of the imple

  • I heard good Ruby and Rails site

    1. Ruby Inside is said to be the best news station, the subscriber number 16xxx [img] http://www.rubyinside.com/simg/logo.gif "alt =" [/ img] http://www.rubyinside.com/ 2. Rails Inside is also a news station, the subscriber number of 3xxx [ ...

  • IBM Ajax Tutorial Series

    Links: http://ibm.csdn.net/ISN_J.aspx?action=JMP&pointid=1550 Part 10: Using JSON for data transmission In the asynchronous application to send and receive information, you can choose to plain text and XML as data format. Ajax grasp of this issue ...

  • Hibernate in the inverse and cascade

    First of all, to quote another blog saying: 1.cascade ="..."? cascade is not a property of many-to-many relationship must have it just so that we insert or delete at the time like some more convenient, as long as the source of the cascade insert

  • To a generic hibernate example DAO

    Reprint: http://blog.csdn.net/dingx package sgf4web.dao; import java.io.Serializable; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.hibernate.*; import org.hibernate.criterion.*; import org.springframework.

  • Software development sunflower Baodian [reprint]

    Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used

  • JS in the Date type conversion


  • Java technology 25 study points

    1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic

  • JAVA interview questions

    JAVA interview questions 1, object-oriented features of what has 1. Abstract 2. Inheritance 3. Packaging 4. Polymorphisms 2, String data types are the most basic right? Basic data types include byte, int, char, long, float, double, boolean and short. java

  • Java Technology wishing cow needed 25 points of study

    1. You need to master the object-oriented analysis and design (OOA / OOD), involving patterns (GOF, J2EEDP) as well as the integrated model. You should understand the UML, especially class, object, interaction and statediagrams. 2. You need to learn basic

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries