Ios Same Operation Simulator Has No Memory Leak Real Machine Debugging Memory Continues to Increase

  ios, question

For example, my xcode5.1 ios7.1sdk is itouch5 Prison Break ios7.06sdk

For example, when debugging a real machine, I accidentally found that the memory was increasing. The only step I took was to show the presentViewController and then dissmissViewController looked at the code several times. There should be no problem.
Finally, using Instruments to profile the results on the simulator did not find memory leaks, the same operation, the memory will not always increase.

So ask the great god to answer this question when debugging the real machine.
Is there any other way to test memory leaks besides profile and analyze?

Please don’t answer with arc.

//这是头文件
@interface EditJourneyViewController : UIViewController
@property(nonatomic,retain)UICollectionView *collectionView;
@property(nonatomic,retain)Journey *journey;
@property(nonatomic,assign)int headerTouchedIndex;
@property(nonatomic,retain)UIActivityIndicatorView *activityView;
@property(nonatomic,assign)BOOL isNew;
@property(nonatomic,assign)id<EditJourneyViewProtocol> delegate;
@property(nonatomic,retain)ALAssetsLibrary *library;
@property(nonatomic,retain)NSIndexPath *touchIndexPath;
@property(nonatomic,retain)NSMutableArray *nodePhotos;
@property(nonatomic,retain)MWPhotoBrowser *browser;

- (instancetype)initWithJourney:(Journey *)journey andNew:(BOOL)isNew;
@end

//.m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.headerTouchedIndex = -1;
    NSMutableArray *array = [[NSMutableArray alloc] init];
    self.nodePhotos = array;
    [array release];

    DraggableCollectionViewFlowLayout *collectionViewLayout = [[DraggableCollectionViewFlowLayout alloc] init];
    collectionViewLayout.sectionInset = UIEdgeInsetsMake(heightSpace, leftWidth, heightSpace, rightSpace);
    collectionViewLayout.itemSize = CGSizeMake(imageLength, imageLength);
    collectionViewLayout.minimumInteritemSpacing = imageSpace;
    collectionViewLayout.minimumLineSpacing = imageSpace;
    collectionViewLayout.headerReferenceSize = CGSizeMake(self.collectionView.frame.size.width, headerHeight);
    collectionViewLayout.scrollDirection = UICollectionViewScrollDirectionVertical;

    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:collectionViewLayout];
    [collectionViewLayout release];
    collectionView.draggable = YES;
    [collectionView setDataSource:self];
    [collectionView setDelegate:self];
    [collectionView registerClass:[EditJourneyCell class] forCellWithReuseIdentifier:identifier];
    [collectionView registerClass:[EditJourneyHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifierHeader];
    collectionView.alwaysBounceVertical = YES;
    collectionView.allowsMultipleSelection = NO;
    collectionView.allowsSelection = YES;
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
    [collectionView release];

    EditJourneyBackView *backView = [[EditJourneyBackView alloc] init];
    _collectionView.backgroundView = backView;
    [backView release];

    [self setTitle:self.journey.title];

    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(saveJourney)];
    [self.navigationItem setRightBarButtonItem:rightButton];
    [rightButton release];

    if (!self.isNew) {
    }else{
        self.navigationItem.hidesBackButton = YES;
    }


    //工具栏

    //新建节点
    UIBarButtonItem *newNode = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(toolbarTouched:)];
    newNode.tag = 0;
    //照相机
    UIBarButtonItem *camera = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(toolbarTouched:)];
    camera.tag = 1;
    //旅程评论
    UIBarButtonItem *comments = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(toolbarTouched:)];
    comments.tag = 2;
    //背景图片
    UIBarButtonItem *backImage = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(toolbarTouched:)];
    backImage.tag = 3;

    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    NSArray *toolbarItems = [NSArray arrayWithObjects:newNode,flexibleSpace,camera,flexibleSpace,comments,flexibleSpace,backImage, nil];

    [newNode release];
    [camera release];
    [comments release];
    [backImage release];
    [flexibleSpace release];

    [self setToolbarItems:toolbarItems animated:YES];

}

- (instancetype)initWithJourney:(Journey *)journey andNew:(BOOL)isNew
{
    if (self = [super init]) {
        self.isNew = isNew;

        self.journey = journey;
        self.journey.journeyDate = [NSDate date];

        self.headerTouchedIndex = -1;

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editNodeName:) name:@"editNodeName" object:nil];;

    }

    return self;
}

- (void)dealloc
{
    if (_touchIndexPath) {
        self.touchIndexPath = nil;
    }
    if (_browser) {
        self.browser = nil;
    }
    self.nodePhotos = nil;
    self.journey = nil;
    self.activityView = nil;
    self.delegate = nil;
    self.library = nil;
    self.collectionView.delegate = nil;
    self.collectionView.dataSource = nil;
    self.collectionView = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"editNodeName" object:nil];
    [super dealloc];
}


//presentViewController 在上个界面
int count = [self.createdJourneys count];
            Journey *newJourney = [[self.createdJourneys objectAtIndex:count - 1] retain];
            EditJourneyViewController *editJourneyView = [[EditJourneyViewController alloc] initWithJourney:newJourney andNew:NO];
            editJourneyView.delegate = self;
            [newJourney release];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editJourneyView];
            [editJourneyView release];
            [self presentViewController:nav animated:YES completion:nil];
            [nav release];


//dismissController
    [[NSNotificationCenter defaultCenter] postNotificationName:@"convertToMineView" object:nil];
    [self dismissViewControllerAnimated:YES completion:^{

        NSLog(@"save");
    }];

Could it be that the relevant autorelease pool has not been released yet? Therefore, the memory occupied is increasing, but analyze will not report warning! This is relatively easy to verify. You put the relevant code in a self-built autorelease pool inside, dismissViewController, and then release the pool!

Ps. Seek to paste code, it is easier to see if there is a problem! 😀