IOS development: the solution for the continuous increase of MKMapView map memory, iosmkmapview

Source: Internet
Author: User

IOS development: the solution for the continuous increase of MKMapView map memory, iosmkmapview

Recently, a project that uses MKMapView has been modified, and the memory usage has been too high. It also increases the usage every time you drag a map and cannot be released.

After two days of troubleshooting, the final lock is to apply for memory when the self. map object is loaded, but it will not be released during the life cycle of the View.

After reading the information, I learned that removeFromSuperview can release the memory, but the map will disappear from the parent View if I remove it.

The final solution is to add two lines of code to-(void) mapView :( MKMapView *) mapView regionDidChangeAnimated :( BOOL) animated.

[Self. map removeFromSuperview]; [self. view addSubview: mapView];

When self. map is removed, the mapView is reloaded, and the two lines of code can be used to release the memory.

According to the Instruments test, memory that cannot be released can be released. The Malloc 4.00 MB in is the memory applied for the map. A total of 164 MB is applied. After MB is released, only 28 MB is needed for the map memory when the program runs smoothly.

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.