首页 > ios 同一操作模拟器无内存泄露 真机调试内存不断增加

ios 同一操作模拟器无内存泄露 真机调试内存不断增加

如题,本人用的xcode5.1 ios7.1sdk 机子是itouch5 越狱 ios7.06sdk

如题,真机调试的时候意外发现内存不断增加,我操作的步骤只是presentViewController 然后dissmissViewController 反复看了好几遍代码 应该没有问题。
最后用 Instruments 在模拟器上profile 结果没有发现内存泄露,同样的操作,内存不会一直增加。

所以求大神解答下真机调试时这种情况是怎么回事?
还有求介绍下除了profile 和 analyze 外,有其他方法测试内存泄露的吗?

ps.求不要回答用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");
    }];



会不会是相关的autorelease pool还没有释放掉? 所以占用的内存在增加, 但是analyze也不会报warning! 这个比较好验证, 你把相关的代码放在一个自建的autorelease pool里, dismissViewController后, 释放掉pool!

ps. 求贴代码, 比较容易能看出是不是有问题! :D

【热门文章】
【热门文章】