Eclipse rap rich client Development Summary (12)-destruction of components optimized by rap

Source: Internet
Author: User
Note: Eclipse rap rich client Development Summary-a series of articles are transplanted from my iteye blog. Later will directly update the http://jlins.iteye.com/
I. Overview 
After several months of practice in the RAP project, I have summarized some small experiences. I would like to summarize them here and hope to help you.

Ii. Disposal of destruction 

I believe everyone who learns rap knows that SWT provides many components, such as label, button, and text. These components are widely used in practice, of course, the specific usage will not be introduced here, mainly in our actual application process, that is, remember to destroy components after use.
In our project, a large number of label components are applied in our project, and features are frequently added and deleted. In this case, a large number of useless labels are generated. If these labels are not destroyed, some space resources will be occupied. At first, I did not take this issue into account when I was working on the project. I frequently experienced memory overflow. I didn't see much data on the interface. Later I found that, these were originally hidden and useless label islands. In the logic, call the label's dispose () method when the label is used up. However, you must ensure that the label is dispose () after it is used. Otherwise, the component will become invalid.

Iii. Handling of Special Cases 

The dispose method of a component is used to destroy the resources temporarily used by the current component. However, you can destroy the current component without calling the dispose method. This is also related to the object Association in the component. in addition, the single-thread implementation mechanism of rap itself causes some objects to be resident in the memory, which causes the objects to fail to be destroyed normally.
For example, when using RCP/RAP, you must implement many composite objects. Each composite object can also call references of many other composite, resources, or other objects, at this time, if you call the dispose () method of the current object, the current object cannot be destroyed because many resources in the object exist and are not destroyed, in particular, when the relationship between classes is complex, it is impossible to destroy objects.
Processing Method: when implementing a composite object, you must override dispose (). In this method, you must release all resources, such as database resources and object references. Ensure that all references are left blank, this improves the recovery speed of virtual machines.

4. How to check whether objects in the program are released normally 

You can use jprofile to analyze the memory to determine whether an object is normally released. jprofile can also display the reference of each object and object on the interface, so that you can have a clear view of memory problems.
Related Article

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.