ios - How to observe the dealloc process -
in app i'm downloading location data , showing them on map. there scenarios cannot understand why happening. sometimes, mapview(google map) class dealloc
getting called , i'm unable see markers on map(i can still see current location).
this how mapview setup in storyboard:
[containervc] -embedsegue->[mapview]
container vc root vc.
and in rootvc class:
@property (weak, nonatomic) mapvc *mapvc; - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if ([[segue identifier] isequaltostring: @"embeddedmapvc"]) { self.mapvc = [segue destinationviewcontroller]; self.mapvc.delegate = self; } }
and in mapvc class(all properties strong,nonatomic):
-(void)viewdidappear:(bool)animated{ [super viewdidappear:animated]; [self setupmapview]; } - (void)setupmapview{ mylog(@"map view refreshed/setup"); //set map view self.infowindow = [[mymapinfowindow alloc] initwithframe:cgrectmake(0, 0, 210, 47)]; self.infowindow.delegate = self; cllocation *center = [[mylocationmonitor sharedinstance] getlocation]; gmscameraposition *camera = [gmscameraposition camerawithlatitude:center.coordinate.latitude longitude:center.coordinate.longitude zoom:18]; self.mapview = [gmsmapview mapwithframe:cgrectzero camera:camera]; self.mapview.camera=camera; [self.mapview setmaptype:kgmstypenormal]; [self.mapview setminzoom:14 maxzoom:18]; [self.mapview setdelegate:self]; self.mapview.mylocationenabled=yes; self.mapview.settings.rotategestures = no; self.mapview.settings.mylocationbutton = yes; [self.mapview setpadding:uiedgeinsetsmake(0, 0, 62, 0)]; self.view = self.mapview; [self setupmarkers]; } - (void)setupmarkers{ mylog(@"setting markers"); self.annotations = nil; [self.mapview clear]; [[mylocationmonitor sharedinstance] getbuildingswithcompletion:^(bool success, nsarray *buildings) { self.buildings = buildings; mylog(@"_buildings_: %@", self.buildings); if (success) { gmscoordinatebounds *bounds = [[gmscoordinatebounds alloc] init]; self.annotations = [[nsmutablearray alloc] init]; (nsdictionary *location in buildings) { cllocationcoordinate2d coordinate = cllocationcoordinate2dmake([[location objectforkey:@"latitude"] doublevalue], [[location objectforkey:@"longitude"] doublevalue]); bounds = [bounds includingcoordinate:coordinate]; gmsmarker *marker = [gmsmarker markerwithposition:coordinate]; marker.title = [location objectforkey:@"name"]; marker.map = self.mapview; marker.icon = [uiimage imagenamed:@"boost-buildingmarkericon"]; marker.userdata = @{@"building":location}; marker.infowindowanchor = cgpointmake(1.0f, -0.1f); marker.opacity = 1.0; [self.annotations addobject:marker]; } [self.mapview animatewithcameraupdate:[gmscameraupdate fitbounds:bounds withpadding:50.0]]; } }]; } -(void)dealloc{ mylog(@"mapvc dealloc called"); }
so, rootvc
move controller , after finish network call comeback rootvc, prepareforsegue
gets triggered , call goes mapvc class, , setups mapview(in process mapvc dealloc gets called in case, i'm unable see markers on map).
i couldn't info stacktrace. know why mapvc getting deallocated ? how make sure mapvc not deallocated @ time ?
edit:
i logged mapvc self in dealloc case:
<mapvc: 0x7ff83f2883c0> on didappear <mapvc: 0x7ff83f2883c0> on dealloc (why happening ?) <mapvc: 0x7ff84475b6f0> new instance again on viewdidappear
how make sure mapvc not deallocated @ time ?
if require vc exist @ time when not onscreen (or @ least in navigation stack), have broken mvc. don't think that's quite what's happening here, it's important keep in mind. network operations should happen in model layer, , view layer should observe model. view controllers responsible managing views visible, not network operations. have organized view controllers incorrectly.
that said, isn't actual problem in case. problem nothing retaining mapvc
. it's weak
in root view controller it's being released segue complete (the segue retains while running). if mapvc
embedded in root view controller, should strong
.
Comments
Post a Comment