响应 didReceiveMemoryWarning 异常
所以我有一张地图,上面覆盖着一堆 MKPolygonViews。当我把几个放在上面时,会有点突兀,然后如果我把它们全部放在系统上,则会向系统发送一个 didReceiveMemoryWarning ,我已通过删除覆盖来响应该系统。
现在我想知道发生这种情况时它实际使用了多少内存,它只有 10MB 实际内存和 100MB 虚拟内存。当时的短信应用程序使用 30MB 内存并且运行良好。还有其他应用程序(例如邮件)使用的内容比我的应用程序更多。 SpringBoard 增加了 5MB,所以没什么特别的。这也在 iPhone 4 上运行,所以应该还有足够的内存(我的计算是大约 256MB 仍然可用)。
在我移除覆盖层后,内存占用仅减少了约 1MB,当我重新打开它们时,内存占用增加了 1MB,所以没有什么异常。
那么这是怎么回事呢?内存警告是否来自图形内存或其他什么?这些覆盖层的性能是否受到图形处理器的限制?当它们全部打开时,它在移动时确实使用了大约 60%,但这并不能解释性能不佳的原因。
任何对答案的指示将不胜感激。
编辑:当覆盖打开时,Springboards 虚拟内存会上升到 450MB,一旦达到 512MB,它就会发送内存警告。这是导致问题的原因吗? VM 总大小始终高于 512MB,因此它必须使用 VM 的闪存,因此不应导致内存警告
So I have a map with a heap of MKPolygonViews overlaid. When I put a couple on it chugs a bit and then if I put them all on the systems sends a didReceiveMemoryWarning to the system that I've responded to by removing the overlays.
Now I wondered how much memory it was actually using when this happens, it's only 10MB real memory and 100MB virtual memory. The SMS app at the time was using 30MB of memory and was running fine. There are also other Apps like mail using more than my App. SpringBoard rises 5MB so nothing too special. This is also running on an iPhone 4 so there should be plenty of memory left (my calculations is about 256MB still free).
After I remove the overlays the memory foot print only goes down about 1MB, when I turn them back on it goes up 1MB so nothing unusual.
So what is going on? Is the memory warning coming from the perhaps the graphics memory or something? Is its performance with these overlays being limited by the graphics processor? With them all turned on it does use about 60% when moving around but that wouldn't explain the bad performance.
Any direction to the answer would be appreciated.
EDIT: Springboards Virtual memory rises to 450MB with the overlays turned on and as soon as it reaches 512MB it sends a memory warning. Is this whats causing the issue? The total VM is always above 512MB so it must be using the flash storage for the VM and thus shouldn't cause a memory warning
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案是将所有 MKPolygonView 合并为一个 MKpolygonView。更多详细信息可以在此处找到
The solution was to merge all the MKPolygonViews into one MKpolygonView. Further details can be found here
您可能应该通过仅显示当前地图上实际可见的那些叠加视图来优化该代码。为用户未查看的地图区域添加叠加视图是没有意义的。
You should probably optimize that code by only showing those overlay views that are actually visible on the current map. There is no point in adding overlay views for an area of the map that the user is not looking at.
我注意到的一件事是,简单地从地图视图中删除叠加层(如 mkpolygon)是不够的。至少有两件事没有发生...
这会导致许多问题,特别是如果您可能正在使用许多大型叠加层。我做了一些事情来抵消这个问题。
这是我能够更改屏幕上的多边形覆盖、彻底清除旧多边形并强制释放内存的唯一方法。
当然,如果有更好、更有效的方法来完成这一切,我愿意接受建议!
One thing I've noticed is that simply removing the overlays (like mkpolygon) from the mapview isn't enough. At least two things aren't happening...
This causes a number of problems, particularly if you're potentially working with a number of large overlays. I did a few things to counteract this.
This was the only way I could manage to change the polygon overlays on the screen, cleanly clear out the old polygons, and force a memory release.
If there's a better, more effective way to do all that, I'm open to suggestions, of course!