Using Optimizeit to detect Java memory leaks

Source: Internet
Author: User

Java programs can also cause memory leaks are open to the secret of the work need to give full attention to the problem.

There are a number of tools on the market for Java memory detection, and I use JBuilder's optimize tools in my work, and now I've done the following on the most recent project and experience using optimize.

Some time ago, according to the need, a Java memory leak test for one of the modules maintained in the work results in a serious problem: the module has 6 basic functions, each operation of each function, about to new consumption of 9-10k memory space, generate about 110 new objects. As a commercial software product, such problems are never allowed to arise.

Optimizeit has integrated into the JBuilder version, also has a separate version, the use is basically the same, it has 4 major functions, can be memory PROFILE,CPU profile, code coverage of the inspection, as well as threads debug, Ability to analyze common applications, jsp/servlet, and server requests. The other is not used, this time the main use of memory profile, found that this is more useful. (In fact, the tools produced by Borland is very useful, but the Borland IDE's current situation is really worrying AH)

The following describes how to use the Optimizeit tool to detect and troubleshoot memory leaks.

First of all, the idea of Detection: program running from a state into the running back to the initial state, the middle process will produce a lot of objects, and these intermediate products should eventually be cleared away, if not completely clear, the program has a memory leak. In other words, by comparing the type and number of objects in the heap memory before and after the program is run, you can determine whether there is a memory leak in the program. When the end of the program heap memory objects in the type and number of more than the initial time, the basic can determine the existence of memory leaks in the program.

Next, the process of using Optimizeit detection.

1. The first use of JBuilder to build a operational project, and then carry out the configuration of the project run properties can be Optimizeit at the same time configuration, mainly select the memory leak option (and other options, but rarely).

2. Click the Optimize button on the toolbar to start detection, which is located on the right side of the program run button, with a stopwatch style.

A few tab views are displayed after 3.Optimize startup, and we primarily care about the memory view.

4. The default display in the memory view is the heap memory view, where you can get an object instance of the class that we care about by entering the filter condition under the attempt, in the middle of the view.

5. Run the program to a certain initial state.

6. Back to Opimize, run the garbage collector, in order to mobilize the GC as far as possible, it is recommended to run the GC more than three times (simply click to write down the button).

7. Mark the status of the day by clicking on the pencil-style icon in the upper-right corner of the view.

8. The function of the line program, and then turn off the function, so that the return of the program to the original state, is basically on the optimize to mark the moment of the interface.

9.Optimize heap Memory View, multiple GC.

10.timize reports changes in memory objects (instances) since the most recent token. Since we have filtered, imize does not show the case of objects other than the package (or class) we care about.

With this comparison, we can find out if there is a memory leak in the program.

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.