Memory usage of MKMapView is very high

依然范特西╮ 提交于 2020-01-13 19:43:51

问题


So i have a UIScrollView with UIPageControl which has a bunch of MKMapViews (mostly 15 different maps). The app is really sluggish once this view loads and after a few minutes of usage i get a memory warning. I looked at it in Instruments and the maps take an insanely high chunk of memory. Even upto ~200mb sometimes. One thing i can think of is to reuse the mapViews. But because of how the views are structured the coding complexity increases. Any suggestions how i can improve performance?

This is how my app is structured:

I have a view controller which has a UIScrollView which i use for horizontal scrolling. In the scrollView i read subviews from an array of view controllers which contains the mkmapview.

Hope that made sense! I used Apple's pageControl sample app as a point of reference while coding so the design is roughly similar.

Thanks in advance!

EDIT: So i tried adding a single instance of the mapView and changing the coordinates on swiping. It still takes a decent amount of memory.


回答1:


To scroll through an arbitrary number of pages in a scroll view you only need two content views, not 15. That's because there'll never be more than two content views visible at any given time. You can re-layout your content in the UIScrollView delegate's -scrollViewDidScroll: method.



来源:https://stackoverflow.com/questions/11982924/memory-usage-of-mkmapview-is-very-high

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!