响应 didReceiveMemoryWarning 异常

发布于 2024-09-15 16:36:12 字数 622 浏览 7 评论 0原文

所以我有一张地图,上面覆盖着一堆 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不顾 2024-09-22 16:36:12

解决方案是将所有 MKPolygonView 合并为一个 MKpolygonView。更多详细信息可以在此处找到

The solution was to merge all the MKPolygonViews into one MKpolygonView. Further details can be found here

北渚 2024-09-22 16:36:12

您可能应该通过仅显示当前地图上实际可见的那些叠加视图来优化该代码。为用户未查看的地图区域添加叠加视图是没有意义的。

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.

萌面超妹 2024-09-22 16:36:12

我注意到的一件事是,简单地从地图视图中删除叠加层(如 mkpolygon)是不够的。至少有两件事没有发生...

  1. 它没有释放所有内存
  2. 它没有从地图视图中完全清除叠加层

这会导致许多问题,特别是如果您可能正在使用许多大型叠加层。我做了一些事情来抵消这个问题。

  1. 我无法按照 AppleDevForum 帖子中的建议将它们全部塞入一个 MKPolygonView 或“MultiPolygonView”中,因为我的目标是 iOS 3.2,这排除了对这些“仅 iOS 4”类进行子类化...您仍然可以在 3.2 中使用它们,只是不将它们子类化
  2. 由于我的多边形中的坐标数量非常多,所以我决定将屏幕上的数量随时限制为两个。碰巧,对于我的申请来说,这是一个合适的期望。因此,我将两个多边形视图存储为地图视图控制器的属性,并根据需要重用它们。
  3. 每当我需要释放内存(经常!)或每当我需要更改多边形时,我首先通过调用 [polygonView invalidatePath] 使相应的多边形视图路径无效。只有在那之后,我才会重置多边形视图属性,然后从地图视图中删除叠加层(在必要时重新创建它们之前)。

这是我能够更改屏幕上的多边形覆盖、彻底清除旧多边形并强制释放内存的唯一方法。

当然,如果有更好、更有效的方法来完成这一切,我愿意接受建议!

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...

  1. It's not releasing all the memory
  2. It's not cleanly clearing the overlay completely from the map view

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.

  1. I couldn't cram them all into one MKPolygonView or "MultiPolygonView" as suggested in the AppleDevForum posting, because I'm targeting iOS 3.2, which precludes subclassing these "iOS 4 only" classes ... you can still use them in 3.2, just not subclass them
  2. Decided that due to the very high number of coordinates in my polygons, I'm limiting the number on screen at any time to two. It just so happens that for my application, this was an appropriate expectation. So I store the two polygon views as properties for my map view controller, and reuse them as necessary.
  3. Whenever I need to free memory (often!) or whenever I need to change the polygons, I first invalidate the appropriate polygon view paths with a call to [polygonView invalidatePath]. Only after that do I reset the polygonview property, and then remove the overlays from the map view (before recreating them if necessary).

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文