Nikhil.T
Nikhil.T

Reputation: 261

Dealloc is not calling immediately after release

I have a root view that loads two view controller. e.g.:FirstVC,SecondVC.

I am showing FirstVC as the root view controller when the app launches, on some action on FirstVC I load SecondVC by removing first.

For loading SecondVC I first remove FirstVC by

[FirstVCobj.view removeFromSuperView];  
[FirstVCobj release];
FirstVCobj = nil;

After that I allocate and create SecondVC

Now only after calling SecondVC's viewdidload() is FirstVC's dealloc() method called. Is this the right execution path, or is it due to some mistake I have made? The above is exactly how I remove and create my view controllers.

Upvotes: 0

Views: 345

Answers (2)

Daij-Djan
Daij-Djan

Reputation: 50129

i assume it is a UIView you're talking about.


  • addSubview retains the view
  • removeFromSuperView releases or AUTORELEASES it -- an implementation detail you don't control

to 'see' it: wrap it in a pool of your own

@autoreleasepool {
    [FirstVCobj.view removeFromSuperView];  
    [FirstVCobj release];
    FirstVCobj = nil;
}

Upvotes: 1

satishiOS25
satishiOS25

Reputation: 531

[FirstVCobj removeFromParentAndCleanup:YES];

Check with this might work.

Upvotes: 0

Related Questions