小弟新人,求大神们帮忙,内存未泄露,但是tableviewcell 数据源刷新内存持续上涨 内存数据uitableviewcell 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道为什么如果我注释掉cell.textLabel.text = [[_chapterList objectAtIndex:row]objectForKey:@"type_name"];这句的话内存虽然增长但是没原来那么多 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 部分的数据源 //选中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]; }}选中部分的代码,每次选中或返回内存都会增长 这倒是没有,那怎么测那僵尸对象。呵呵,不好意思啊,由于刚刚从事ios开发,不知道怎么弄 测了下,用instruments测试了下没发现僵尸对象 Quote: 引用 6 楼 zhangao0086 的回复:看起来还是没问题,你有没有把僵尸对象打开我用instrucments allocations 测试下了下 显示如图, instrucments显示占用的内存和Xcode显示占用的内存是一样的吗? 我看了下,不一样,instrucments 远小于xcode中的占用内存大小,如instrucments 13M开始回落到8M左右,而同样情况xcode要20M,也基本不回落。 恩,那可能是Xcode的问题,instrucments更准一些 但是即使是instrucments 中测试的话,反复进行同样的操作内存还是会持续增长。 对了,我每次刷新数据源之前都要解析网络中的xml,然后把解析到的内容复制到 nsmutablearray 类型的_chapterList数组中,有没可能是这部分问题? 在Xcode里运行Analyze看看。菜单栏-Product-Analyze 也是有可能的: [self startParseType:[_rootArray lastObject]]; [_rootArray removeLastObject]; [_chapterList removeAllObjects]; [_chapterList addObjectsFromArray:[myPlayer typeDataArray]];应该是这四句代码的缘故 Analyze试了下,没有疑似泄露点 额,我也觉得有可能,但是我每次都removeAllObjects 所有的object 然后才add进去,感觉应该没有问题 _rootArray呢myPlayer和它的typeDataArray还有这个方法的实现:startParseType -(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数据 我觉得最有可能的还是数据源刷新的时候,原有的数据没有清干净,这样吧,你的数据源_chapterList里的对象如果是自定义的对象,你就在dealloc里下断点,看数据源刷新的时候原数据有没有释放,如果是字典的话你也可以子类化一个字典,也是看它dealloc方法有没有调用 在ARC下,应该这些数据都会自动清理掉吧。 ARC下一样会发生因为循环引用引起的内存泄漏,还有Timer、通知之类的内存泄漏 ARC下一样会发生因为循环引用引起的内存泄漏,还有Timer、通知之类的内存泄漏不好意思啊,关于子类化NSMutableDictionary,我创建了一个类myNSMutableDictionary继承NSMutableDictionary,除了要在.m中实现-(void)dealloc 外,还要实现哪些函数? 不需要了,只实现dealloc看下就行了 Quote: 引用 25 楼 zhangao0086 的回复:不需要了,只实现dealloc看下就行了[/quote#import "myNSMutablediactionay.h" 我加了头文件后@property(strong, nonatomic) myNSMutablediactionay *typeDict; 提示未知数据类型 关于VNC远程桌面共享 能把UISegmentedControl的布局改为2*3的吗? 想做个答题的应用 希望高手给个思路~ Lable中的字体怎么实现删除线?就是字体上中间加横线 XCode 的#include<> 头文件搜索顺序问题 代码没有起作用 iphone openGLES加载纹理问题 归档解档,数据错误 今天早上收到苹果APP被拒邮件,新手小白求大神帮忙 关于oc的一道题。 XCode6 MainStoryboard 中 storyboardWithName:bundle: Xcode6.0.1下为何没有了“Empty Application”选项
//返回时将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 部分的数据源
- (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];
}
}选中部分的代码,每次选中或返回内存都会增长
菜单栏-Product-Analyze
[self startParseType:[_rootArray lastObject]];
[_rootArray removeLastObject];
[_chapterList removeAllObjects];
[_chapterList addObjectsFromArray:[myPlayer typeDataArray]];
应该是这四句代码的缘故
myPlayer和它的typeDataArray
还有这个方法的实现:startParseType
{
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数据