0
votes

i am developing a ios park guide app which displays a MKMapView. To show our own map we have designed a big size (2499x1504px) jpg overlay image. The MKMapView also displays a view annotations.

I swiped around the mapview and inspected the memory size in the debug navigator and recognized (sometimes, not always) that the memory grows up to 100-180 mb. If the memory is about 150+mb i get a memory warning and the app crashes due memory problems. In simulator the app never crashes.

To test purposes i have removed all overlays and annotations and swiped around again. In some situations the memory also grows up to 100-120mb without memory warning.

My Device: IPhone 4s

The implementation:

if ([overlay isKindOfClass:[LGSOverlay class]]) {
        UIImage *theImage = [UIImage imageNamed:@"overlayImage"];
        XYZOverlayRenderer *overlayRenderer = [[XYZOverlayRenderer alloc] initWithOverlay:overlay overlayImage:theImage];
        return overlayRenderer;
}

XYZOverlayRenderer:

-(id)initWithOverlay:(id<MKOverlay>)overlay overlayImage:(UIImage *)overlayImage {
    self = [super initWithOverlay:overlay];
    if (self) {
        _overlayImage = overlayImage;
    }
    return self;
}

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    CGImageRef imageReferenc = self.overlayImage.CGImage;    

    MKMapRect theMapRect = self.overlay.boundingMapRect;
    CGRect theRect = [self rectForMapRect:theMapRect];

    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -theRect.size.height);
    CGContextDrawImage(context, theRect, imageReferenc);
}

Whats the best solution to solve this problem?

EDIT:

I solved the problem by following this tutorial: http://www.shawngrimes.me/2010/12/mapkit-overlays-session-1-overlay-map/

1

1 Answers

0
votes

The simulator never runs out of memory, so don't think that strange. JPEG images of that size are way too big once converted to a video buffer. The iPhone 4s has 512MB of ram which is shared between GPU and CPU. You might have to find a way to tile the image or make is smaller.

How do you know the crash is due to memory problems? Do you get some memory warnings and then he app is terminated? Maybe there is another issue.

You might also look into using a more native compressed PowerVR format rather than using jpeg. However outside of OpenGL ES I'm not sure how they're supported.

Note that under iOS 6+ Mapkit uses vectors and by itself takes 80-100 MB sometimes to display the map data.