7

I've built a simple application that shows markers on map ,and I load its x,y from JSON file from a server the markers are click-able so once you on any marker it takes you to another UIViewController (Let's name it BViewController). I've monitored the Memory Usage so each time I go back from BViewController to MapViewController (Which is the map inside) it's just double the usage of memory I tried to set it to nill or Remove it from superView , but nothing changed

My Project use ARC.

So please any idea how to reduce this usage.
Thanks in advance

Tulon
  • 4,011
  • 6
  • 36
  • 56
mustafa96m
  • 329
  • 3
  • 16
  • If the Google Maps SDK is leaking memory there may not be much you can do. Check it's not your app first using `Instruments`. Also think about using the built-in Apple Maps instead. – Robotic Cat Oct 18 '13 at 14:19
  • @RoboticCat Thanks for reply :) , I checked it for many times but this problem occurs I think because Reloading The MapView Again with deallocating the previous one do you have any idea how can I avoid re-loading – mustafa96m Oct 18 '13 at 14:32
  • 1
    I'm guessing this is related to the bug report at https://code.google.com/p/gmaps-api-issues/issues/detail?id=5941 yes? If so, you could hold a reference onto the MapViewController in MyViewController and thus not need to recreate it each time you navigate into the sub view controller. – Brett Oct 22 '13 at 04:01

1 Answers1

0

I can't immediately tell what's leading to this without seeing more code, but with "expensive" objects like a GMSMapView, I might make a category to create a shared GMSMapView and add it programmatically if you're not already doing so. Your category might look something like this:

// GMSMapView+MyAdditions.h
#import <GoogleMaps/GoogleMaps.h>
@interface GMSMapView (MyAdditions)
  + (GMSMapView *)sharedMapView;
@end


// GMSMapView+MyAdditions.m
#import "GMSMapView+MyAdditions.h"
@implementation GMSMapView (MyAdditions)

+ (GMSMapView *)sharedMapView {
  static GMSMapView *mapView;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    CLLocation *location = [[CLLocation alloc] initWithLatitude:40.7127 longitude:-74.0059];
    GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithLatitude:location.coordinate.latitude
                                                                    longitude:location.coordinate.longitude
                                                                         zoom:16.0];
    mapView = [GMSMapView mapWithFrame:[UIScreen mainScreen].bounds camera:cameraPosition];
  });
  return mapView;
}

@end
pitachip
  • 965
  • 3
  • 7
  • 24