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/