Grow heap (frag case) heap memory is too large

Source: Internet
Author: User
Tags sqlite database

Although Android Developers use a Java language that can automatically manage memory, improper memory management may lead to frequent usage of apps like info/dalvikvm-heap (10798 ): grow heap (frag case) to 6.437 MB for 1114126-byte allocation
The value after grow heap is increasing. Next, the android system starts to end background tasks to increase the heap memory. In the end, oom may occur directly, at the same time, GC may also cause GC freed 0 objects/0 bytes in 75 Ms. We have recently mentioned the Java memory management, we will give you a simple analysis on these issues.

1. Grow heap (frag case) to 6.437 MB for 1114126-byte allocation indicates that you have been allocating a large object, and the heap memory occupied has reached 6.4 MB.

2. why is there such a problem? After inquiry, it indicates that a byte [] array is allocated, and a single object is large because it needs to be written to the SQLite database in blob mode, here, the android Development Network reminds everyone that this operation is very dangerous. For devices with different firmware and low Ram configurations, there is a danger of OOM at any time. If you really need to store binary data to SQLite, here, we can split an object into 1 MB or smaller segments and store them in more segments. It is better to add a layer of split data cache layer in the middle.

3. at the same time, before constructing a single large object, you can notify the GC to prepare for collection. For example, you can execute system before execution of the required operation. GC (); prevents outofmemoryerror. For Java memory overflow, we will explain it through various cases in the future.

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.