简体   繁体   中英

Modally presented UIViewController does not empty memory on close

I have a problem, that caused me quite some hours/days of debugging so far.

My situation is:

  • i have a viewcontroller that displays some data
  • when a user clicks a button another view controller is presented modally
  • after the user closes the modal controller, the memory usage does not decrease

I do not hold references (either weak or strong) for the modal view anywhere.

This is how the segue is performed:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   UINavigationController *nav = [segue destinationViewController];
   SomeViewController *vc = (SomeViewController *)[nav topViewController];
   vc.dataArray = self.dataArray; // dataArray is a weak reference
}

And this is how i close it:

-(void)closeButtonClickHandler:(id)sender
{
   [self dismissViewControllerAnimated:YES completion:nil];
}

In my viewDidDisapear method, i set everything to nil

- (void)viewDidDisappear:(BOOL)animated
{
    [self.map removeAnnotations:self.myMap.annotations];
    self.map.delegate = nil;
    self.map = nil;

    self.view = nil;

    [super viewDidDisappear:animated];
}

But the controller still remains in memory. What is even worse is, that if i open it multiple times, it keeps adding to the consumed memory until eventually the OS is forced to close the application.

Any/all help is appreciated :)

I of found out that a small side view had a wrong reference set. It was 'strong', should have been 'weak'

@property (nonatomic, weak) UISomeView * someView;

After that the memory was released normally and did not stack up any more

tnx @JonathanCicohons for the hint :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM