1

I create very simple project with NAvigation controller which root controller is viewController with only one button that point on new mapViewControler that contains mapView.

NavigatioController --> viewController - button --push--> mapViewController with mapView.

This is my code for mapViewController.h:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface mapViewController : UIViewController

@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

This is my code for mapViewController.m:

#import "mapViewController.h"    

@implementation mapViewController       
- (void)viewDidLoad
{
    [super viewDidLoad];        
}

-(void) viewWillDisappear:(BOOL)animated {

   //trigered when Back button pressed
   if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        [self setMapView:nil];
        self.mapView.delegate = nil;
    }
    [super viewWillDisappear:animated];
}
@end

So when I click button(segue - push), the mapViewController shows up and Live Bytes increase for 40MB - I suppose because of the map images, but when I click back button (navigationControl) the memory decrease only for 39 MB. So 1MB stays somewhere. If I repeat this 100 times this is 100MB. The Leaks tool shows no leaks.

Can somebody explain why this 1MB stays every time I click Back and how to get rid of it?

ButterBeast
  • 521
  • 10
  • 25
  • This may not solve your problem but try calling [super viewWillDisappear:animated]; before if condition. – parilogic Mar 07 '13 at 13:47
  • 1
    I don't have time to give a fully researched answer, but wanted to give you something to think on. viewWillDisappear may not be doing all you expect it to do. There's an animated transition back to the previous view, and the app has to retain some info to complete the animation. Look into releasing that view once you fully enter the previous view. Have you put an NSLOG into that viewWillDisappear statement to make sure it's actually being called? – BobbyScon Mar 07 '13 at 14:04
  • I add NSLOG and the program go in to if statement. – ButterBeast Mar 07 '13 at 15:25
  • Thanks for your answer. Can you help me where to find examples, documentations or guideline how to releasing previous view when fully enter to parent view. – ButterBeast Mar 07 '13 at 15:29
  • Which version of iOS are you writing for, and do you have ARC enabled? – Craig Mar 07 '13 at 19:21
  • 6.0 and yes ARC is enabled – ButterBeast Mar 08 '13 at 10:10
  • Sorry, I haven't worked with 6.0+ yet, and I know some things have changed as far as retains and releases. Check this thread and see if it will at least help you identify what's not being released properly. http://stackoverflow.com/questions/5587509/is-there-a-way-to-find-mystery-retains – BobbyScon Mar 12 '13 at 17:13

0 Answers0