Reduce the generation of Java garbage and reduce the amount of memory used

Source: Internet
Author: User

1. Use as few static variables as possible, as it will always consume memory,

2. Use as few string strings as possible for stitching and adding. Because a string is a fixed length, each addition creates a new temporary object, generates a garbage object, and uses StringBuffer as much as possible because the StringBuffer is variable length.

3. When the object is exhausted, the null value is used so that the JVM garbage collection will not be judged and recycled directly.

4. Try not to display the call System.GC ().

Reduce the generation of Java garbage and reduce the amount of memory used

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.