问题描述
是否有其他人在iOS 6应用程序中使用地图,注意到内存使用极高以至于一直收到内存警告而导致应用程序崩溃?
Has anyone else, who's using maps in their iOS 6 apps, noticing extremely high memory use to the point of receiving memory warnings over and over to the point of crashing the app?
我通过乐器运行应用程序并且我没有看到任何泄漏,并且在创建地图视图之前,应用程序始终以约3mb Live Bytes运行。创建地图并下载切片后,Live Bytes会跳至~13mb Live Bytes。然后当我移动地图并放大和缩小Live Bytes连续体时,直到应用程序崩溃在大约40mb Live Bytes。顺便说一句,这是在iPhone 4上。在iPod touch上,它甚至更早崩溃。
I've ran the app through instruments and I'm not seeing any leaks and until the map view is created the app consistently runs at around ~3mb Live Bytes. Once the map is created and the tiles are downloaded the Live Bytes jumps up to ~13mb Live Bytes. Then as I move the map around and zoom in and out the Live Bytes continuos to climb until the app crashes at around ~40mb Live Bytes. This is on an iPhone 4 by the way. On an iPod touch it crashes even earlier.
我正在重复使用注释视图,没有任何泄漏。有没有其他人看到与新的iOS 6地图相同的高内存使用率?还有,有没有人有解决方案?
I am reusing annotation views properly and nothing is leaking. Is anyone else seeing this same high memory usage with the new iOS 6 maps? Also, does anyone have a solution?
推荐答案
经过大量的游戏和测试不同的想法,其中一些在这里提到,对我有用的最终解决方案如下。
After a lot of playing around and testing different ideas, some of which were mentioned here, the final solution that worked for me was as follows.
-
我没有在应用程序中根据需要创建新的MKMapView,我的AppDelegate的mkMapView属性,只在需要时创建它。一旦创建它,它永远存在于AppDelegate中,我在所需的任何地方重用该单个实例。这确实有助于减少使用的内存量,因为我之前实例化了几个不同的MKMapView,并且两者都很快地通过内存刻录。
Instead of creating new MKMapView's as needed in the app, I added an mkMapView property to my AppDelegate and only created it when needed. Once it has been created, it lives in the AppDelegate forever and I reuse that single instance everywhere needed. This really helped in reducing the amount of memory being used as I was previously instantiating a couple different MKMapView's and both were burning through memory pretty quickly.
我也发现了一旦收到内存警告,iOS 6 Maps就可以很好地释放内存。是的,它在缩放和平移时会耗尽更多内存,但似乎正在适当地响应内存警告。
I also found that iOS 6 Maps handles releasing memory very well once a Memory Warning has been received. Yes, it does use up more memory while zooming and panning, but seems to be responding to Memory Warnings appropriately.
我要做的最后一件事就是工作减少我的整体初始内存占用。我注意到我的起步比我预期的要高,这也导致我收到的与内存有关的崩溃。一旦我得到初始足迹,让MKMapView处理在内存警告期间释放它的内存,并确保我只有一个MKMapView实例,我可以在整个应用程序中重复使用,一切运行正常。
The last thing I had to do was work on reducing my overall initial memory footprint. I noticed I was starting off way higher than I expected so that was also contributing to the crashes I was receiving related to memory. Once I got the initial footprint down, let MKMapView handle releasing it's memory during Memory Warnings, and made sure I only had 1 instance of MKMapView that I could reuse throughout the app, everything is running fine.
这篇关于iOS6 MKMapView使用了大量的内存,到了崩溃的应用程序,其他人都注意到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!