views:

158

answers:

3

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

A: 

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.

St3fan
They are not being drawn until they are visible on the map. Once they are off screen the App performance returns to normal.
Rudiger
A: 

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

Rudiger
A: 

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!

Greg Combs
Thats odd that you can use them but not subclass them. I removed the polygonView in my didReceiveMemoryWarning using the removeOverlay function and it was clean as far as memory reallocation was concerned but it might be different in 3.2
Rudiger