iOS6 MKMapView 使用大量内存,以至于应用程序崩溃,还有人注意到这一点吗? [英] iOS6 MKMapView using a ton of memory, to the point of crashing the app, anyone else notice this?
问题描述
有没有其他人在他们的 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 会跃升至 ~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 在内存警告期间处理释放它的内存,并确保我只有 1 个 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 使用大量内存,以至于应用程序崩溃,还有人注意到这一点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!