Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Flex memory optimization principle and example analysis of memory leak

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the example analysis of Flex memory optimization principles and memory leaks. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Common methods of Flex performance Optimization

As we all know, at present, domestic broadband applications are not as developed as many developed countries, and the bandwidth of personal applications is basically less than 2m. How to make your Flex applications run smoothly on the client has become a big problem restricting every Flex application development programmer. Here, I have collected and sorted out the experience in this area on the Internet. You are welcome to add it.

Flex memory release optimization principle

1. All external references to the deleted object must be deleted before they can be treated as garbage collection by the system.

two。 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, and the parent object will not be deleted.

3. If an external object is referenced in an object, when you are deleted or do not need to use this reference object, be sure to set the reference of this object to null

4. The reason why this object cannot be deleted is not necessarily that it has been referenced, but also that its own child is referenced externally, and the father cannot delete it because the child cannot delete it.

5. In addition to references that need to be deleted, system components or global tools or management classes that provide uninstall methods must be called to delete internal objects, otherwise memory leaks and performance losses may occur.

6. If the parent object is deleted immediately, it does not mean that the child object will be deleted or deleted immediately, and may be deleted later when it is automatically deleted by the system or when it is removed for the second time.

7. If the parent object remove the child object without clearing the reference to 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 will not affect the custom forced collection mechanism, but it may affect the normal recovery mechanism, so * make sure that all registered event listeners should be removed clean.

9. The deletion of the parent object does not mean that the rest of the child objects are deleted. The leaked code in one state does not mean that there is no leakage in other states. Each module should be tested and analyzed one by one in each state until the entire object can be deleted in any state of the test.

Examples of Flex memory leaks:

1. Reference disclosure:

Null is required for references to sub-objects and external references to this object or sub-objects.

two。 System class disclosure:

Use the system class and forget to do delete operations, such as BindingUtils.bindSetter (), ChangeWatcher.watch () function after the end of the need to call ChangeWatcher.unwatch () function to clear the reference, otherwise the object using this function will not be deleted; similar to MUSIC,VIDEO,IMAGE,TIMER,EVENT,BINDING and so on.

3. Effect leakage:

When applying the effect Effect to the component, when the object is deleted, you need to stop the Effect animation on the object and sub-objects, and then set the target object of Effect to null;. If you do not stop the animation and directly set the Effect to null, the object will not be removed normally.

4.SWF disclosure:

To completely delete a SWF, call its unload () method and set the object to null

5. Picture leaked:

Set the source to null; (for testing) when the Image object is finished.

6. Voice and video leaks:

When you don't need a music or video, you need to stop the music, delete the object, and set the reference to null.

This is the end of this article on "Flex memory optimization principles and sample analysis of memory leaks". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 207

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report