解决方案 »

  1.   

     不知道为什么如果我注释掉cell.textLabel.text = [[_chapterList objectAtIndex:row]objectForKey:@"type_name"];这句的话内存虽然增长但是没原来那么多
      

  2.   

    isTypeList = YES;
            //返回时将isQuestion置为NO进行解析
            isQuestion = NO;
            //将状态设置为非跳转
            isSugue = NO;
            //取当前rootArray中最后一个id进行解析
            [self startParseType:[_rootArray lastObject]];
            [_rootArray removeLastObject];
            [_chapterList removeAllObjects];
            [_chapterList addObjectsFromArray:[myPlayer typeDataArray]];
            _lineHigh = 44;
            _lines = _chapterList.count;
            [self.tableview reloadData];
            
            if (_rootArray.count == 0) {
                self.backOutlet.enabled = NO;
            }
    这是返回按钮的代码,每次点击返回都是刷新当前页面的tableview 部分的数据源
      

  3.   

    //选中Cell响应事件
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //选中后的反显颜色即刻消失
        //[tableView deselectRowAtIndexPath:indexPath animated:NO];
        NSUInteger row = [indexPath row];
        if (isSugue == NO)
        {
            if (self.backOutlet.enabled == NO) {
                self.backOutlet.enabled = YES;
            }
            
            //防止多次点击以及同父节点的情况,判断当前root是否已经添加,如添加了则不放入rootArray数组中
            NSString *rootName =[[_chapterList objectAtIndex:row] objectForKey:@"type_parent"];
            
            if (![[_rootArray lastObject] isEqualToString:rootName])
            {
                [_rootArray addObject:rootName];
            }
            
            if ([[[_chapterList objectAtIndex:row] objectForKey:@"type_isBigPkg"] isEqualToString:@"True"])
            {
                [self startParseType:[[_chapterList objectAtIndex:row] objectForKey:@"id"]];
                [_chapterList removeAllObjects];
                [_chapterList addObjectsFromArray:[myPlayer typeDataArray]];
                _lineHigh = 44;
                _lines = _chapterList.count;
                //将章节列表标志设为YES,方便搜索时返回判定
                isTypeList = YES;
                
                [self.tableview reloadData];
            }
    }选中部分的代码,每次选中或返回内存都会增长
      

  4.   

    这倒是没有,那怎么测那僵尸对象。呵呵,不好意思啊,由于刚刚从事ios开发,不知道怎么弄
      

  5.   

    测了下,用instruments测试了下没发现僵尸对象
      

  6.   

    Quote: 引用 6 楼 zhangao0086 的回复:

    看起来还是没问题,你有没有把僵尸对象打开我用instrucments allocations 测试下了下 显示如图,
      

  7.   

    instrucments显示占用的内存和Xcode显示占用的内存是一样的吗?
      

  8.   

    我看了下,不一样,instrucments 远小于xcode中的占用内存大小,如instrucments 13M开始回落到8M左右,而同样情况xcode要20M,也基本不回落。
      

  9.   

    恩,那可能是Xcode的问题,instrucments更准一些
      

  10.   

    但是即使是instrucments 中测试的话,反复进行同样的操作内存还是会持续增长。
      

  11.   

    对了,我每次刷新数据源之前都要解析网络中的xml,然后把解析到的内容复制到  nsmutablearray 类型的_chapterList数组中,有没可能是这部分问题?
      

  12.   

    在Xcode里运行Analyze看看。
    菜单栏-Product-Analyze
      

  13.   

    也是有可能的:
            [self startParseType:[_rootArray lastObject]];
            [_rootArray removeLastObject];
            [_chapterList removeAllObjects];
            [_chapterList addObjectsFromArray:[myPlayer typeDataArray]];
    应该是这四句代码的缘故
      

  14.   

     Analyze试了下,没有疑似泄露点
      

  15.   

    额,我也觉得有可能,但是我每次都removeAllObjects 所有的object 然后才add进去,感觉应该没有问题
      

  16.   

    _rootArray呢
    myPlayer和它的typeDataArray
    还有这个方法的实现:startParseType
      

  17.   

    -(void)startParseType:(NSString *)parentId
    {
        NSMutableString *url = [[NSMutableString alloc]initWithString:@"http:XXXXXX"];
        [url appendString:parentId];
        [myPlayer StartParse:url isWebXmlLink:YES]; 
    }myPlayer和它的typeDataArray在下面:
    //xml文件解析部分
    - (void)parserDidStartDocument:(NSXMLParser *)parser
    {
        @autoreleasepool {
            _disBqArray = [[NSMutableArray alloc] init];
            _dataArray = [[NSMutableArray alloc] init];
            _dict = [[NSMutableDictionary alloc] init];
            _dataTmp = [[NSMutableString alloc] init];
            _actionArray =[[NSMutableArray alloc ]init];
            _titleName = [[NSMutableString alloc] init];
            _color = [[NSMutableString alloc] init];
            _thick = [[NSMutableString alloc] init];
            _clean = [[NSMutableArray alloc] init];
            _rubber = [[NSMutableArray alloc] init];
            _imagePages = 0;
            stepTimes = 0;
            
            
            //type地址部分的xml数据解析
            _typeDataTmp = [[NSMutableString alloc] init];
            _typeDict = [[NSMutableDictionary alloc] init];
            _typeDataArray = [[NSMutableArray alloc] init];        //question地址部分的xml数据
            _questionDataTmp = [[NSMutableString alloc] init];
            _questionDict = [[NSMutableDictionary alloc] init];
            _questionDataArray = [[NSMutableArray alloc] init];
        }
    }_rootArray的话也是点返回就把最后一个删除掉了,点cell 加入NSinteger数据
      

  18.   

    我觉得最有可能的还是数据源刷新的时候,原有的数据没有清干净,这样吧,你的数据源_chapterList里的对象如果是自定义的对象,你就在dealloc里下断点,看数据源刷新的时候原数据有没有释放,如果是字典的话你也可以子类化一个字典,也是看它dealloc方法有没有调用
      

  19.   

    在ARC下,应该这些数据都会自动清理掉吧。
      

  20.   

    ARC下一样会发生因为循环引用引起的内存泄漏,还有Timer、通知之类的内存泄漏
      

  21.   

    ARC下一样会发生因为循环引用引起的内存泄漏,还有Timer、通知之类的内存泄漏不好意思啊,关于子类化NSMutableDictionary,我创建了一个类myNSMutableDictionary继承NSMutableDictionary,除了要在.m中实现-(void)dealloc 外,还要实现哪些函数?
      

  22.   

    不需要了,只实现dealloc看下就行了
      

  23.   

    Quote: 引用 25 楼 zhangao0086 的回复:

    不需要了,只实现dealloc看下就行了[/quote#import "myNSMutablediactionay.h" 我加了头文件后@property(strong, nonatomic) myNSMutablediactionay *typeDict; 提示未知数据类型