objective c - Memory leak when re-logging into the iOS application -


in 1 of application presenting landing view controller shown in code. works fine except fact when logout of application , re-login, same method gets called , end creating new mylandingcontroller keeping old 1 still hanging around. since, assigning property shouldn't auto de-allocate old one? checked , ensured there no other object keep strong reference mylandingcontroller; there weak references though.

- (void)presentmylandingview {     self.navigationcontroller = nil;     [[self.window viewwithtag:100] removefromsuperview];     self.window.backgroundcolor = [uicolor whitecolor];     self.primaryviewcontroller = [[mylandingcontroller alloc] init];     self.navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:self.primaryviewcontroller];     [self.navigationcontroller.navigationbar setbarstyle:uibarstyleblack];     [self.window insertsubview:[self.navigationcontroller view] atindex:1];     self.window.rootviewcontroller = self.navigationcontroller;     [nstimer scheduledtimerwithtimeinterval:.50 target:self selector:@selector(clearsubviews) userinfo:nil repeats:no]; } 

as temporary work around, thought of putting condition if older mylandingcontroller exists use instead of creating new one. fixes leak entire view moved (looks moved navigation bar size).

so, looking answer 2 questions here -

q1) why re-initializing new view controller object property not de-allocating older object.

q2) why re-using existing object (pulled weak reference) not rendering ui - screen moves up?

it leaks because landing controller still in presentation stack, not deallocated -- navigation controller still holds reference.

that - coincidence - answers both questions, view controller should not in presentation stack twice.

you check if exists , in case just

[self.navigationcontroller poptorootviewcontrolleranimated:no]; 

instead of creating instance.


Comments