Flex Memory Optimization

Source: Internet
Author: User

Flex memory release optimization principles:

1. All references of the deleted object must be deleted to be disposed of as garbage collection by the system;
2. If the child object inside the parent object is referenced by other external objects, the child object will not be deleted, and the child object will not be deleted;
3. If an object references an external object, you must remember to set the reference of this object to null when you are deleted or do not need to use this reference object;
4. The reason why this object cannot be deleted may not be because it has been referenced by itself. It may also be because the child has been referenced by external entities and cannot be deleted by the father;
5. In addition to references that need to be deleted, system components, global tools, and management classes must call the detach method to delete internal objects. Otherwise, memory leakage and performance loss may occur;
6. If the parent object is deleted immediately, it does not mean that the child object will be deleted or immediately deleted. It may be deleted after being automatically deleted by the system or during the second removal operation;
7. If the parent object does not clear references to the child object after removing the child object, the child object cannot be deleted, and the parent object cannot be deleted;
8. if the registered event is not removed, it does not affect the custom forced collection mechanism, but it may affect the normal collection mechanism. Therefore, it is best to ensure that all registered event listeners should be deleted.
9. if the parent object is deleted, it does not mean that all other sub-objects are deleted. If the leaked code in one State is not in another state, it will not be leaked. test and analyze each state of each module one by one, the entire object can be deleted in any State of the test.

Example of Memory leakage:

1. Reference leakage: this refers to the reference of the Child object. The external references to this object or sub-object must be set to NULL;
2. system class leakage: You forgot to delete the system class, such as bindingutils. bindsetter (), changewatcher. after the Watch () function is complete, you need to call changewatcher. the unwatch () function clears references. Otherwise, the objects using this function will not be deleted;
Similarly, there are music, video, image, timer, event, binding, and so on.
3. effect leakage: when the effect of effect is applied to the component, when the object is deleted, the effect animation on the object and the sub-object needs to be stopped, and then the target object of effect is set to NULL; if you directly set effect to null without stopping the animation, the object cannot be removed normally.
4. SWF leakage: to completely delete a SWF, call its unload () method and set the object to NULL;
5. Image leakage: After the image object is used, set source to null (for testing );
6. sound and video leakage: if you do not need a music or video, you need to stop the music, delete the object, and set the reference to null;

Memory leakage solution:
1. Perform garbage processing in the removed_from_stage event return of the component (remove all external references (both vo and components need to be deleted), delete the listener, and call the clearing method of the system class)
Remove and then set null to make sure that all objects after being removed or removeall are released in the external reference;
2. use the flex performance optimization tool profile to monitor the project process. You can know which objects have been created in history, which objects have not been deleted, and the number of created objects, memory usage, creation process, and other information;

Conclusion: The key is to clear the file, remember to delete the reference you set, and remember to recycle the system classes you used. If the preceding problem is solved, the user-defined forced recycler may be automatically reclaimed by the system normally.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.