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

What are the optimization principles of Flex memory release

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

Share

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

This article mainly introduces what the Flex memory release optimization principles are, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about 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 call to delete internal objects, otherwise it may cause Flex memory leakage and performance loss.

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 leakage: null is required for references to sub-objects and external references to this object or sub-objects.

two。 System class leak: use the system class and forget to delete the operation, such as BindingUtils.bindSetter (), ChangeWatcher.watch () function needs to be called ChangeWatcher.unwatch () function to clear the reference, otherwise the object using this function will not be deleted

Similarly, there are 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 leak: to completely delete a SWF, call its unload () method and set the object to null

5. Picture leaked: set source to null; (for testing) when the Image object is finished.

6. Audio and video leaks: when you don't need a music or video, you need to stop music, delete objects, and set null by reference.

Flex memory leak workaround:

1. Garbage handling in the REMOVED_FROM_STAGE event return of the component (remove all external references (whether VO or component need to be deleted), delete listeners, call the cleanup method of the system class)

Remove before setting null to ensure that all external references of objects after remove or removeAll are released cleanly.

two。 Using Flex's 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, the number of objects created, the proportion and amount of memory occupied, the creation process and other information.

Summary: the key is to do a good job of cleaning, you should remember to delete the references you set, and you should remember to do a good job of recycling the system classes you have used. If the above problems are solved well, it is possible to be automatically recycled by the system without the need for a custom forced collector.

Thank you for reading this article carefully. I hope the article "what are the Flex memory release optimization principles" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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: 0

*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