【问题标题】:Memory keep increasing when the UITableView scrollingUITableView 滚动时内存不断增加
【发布时间】:2013-06-09 17:27:26
【问题描述】:

有一个奇怪的问题我从来没有遇到过

有一个 array() 包括一些名为 MyClass 的自定义对象,由 JSONKit 解析;

当我继续滚动表格视图时,内存也会不断增加。

但是当替换时

cell.textLabel.text = myclass.name;

cell.textLabel.text = @"cool"; 

cell.textLabel.text = [NSString stringWithFormate:@"a-%d", indexPath.row];

内存保持稳定就可以了

但是如果我使用

cell.textLabel.text = [NSString stringWithFormate:@"a-%@-i",myclass.name, indexPath.row];

它还在不断增加;

它会让我发疯!!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Singers";
    OMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    MyClass *myclass = [self.data objectAtIndex:indexPath.row];
    if (cell == nil){
        cell = [[[OMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];   
    }

    cell.textLabel.text = myclass.name;

    return cell;
}

我的班级

有两个类一个Base另一个继承

基地:

@interface OMBase : NSObject {
    NSMutableDictionary *data;
    NSString *name;
    NSArray *keys;
}

@property (nonatomic, retain) NSString *name;
@property (nonatomic, copy) NSMutableDictionary *data;

@implementation OMBase

@synthesize data, name;


- (void)setData:(NSMutableDictionary *)adata{
    if (data){
        [data release];
        data = nil;
    }
    data = [adata mutableCopy];
}

- (void)dealloc{
    if (keys){
        [keys release];
    }
    [data release];
    [super dealloc];
}

- (id)init{
    if (self = [super init]){
        self.data = [[[NSMutableDictionary alloc] initWithCapacity:20] autorelease];
    }
    return self;
}

继承:

#import "OMBase.h"

@interface OMLyric : OMBase

- (NSString *)songid;
- (NSString *)content;

#import "OMLyric.h"

@implementation OMLyric

- (NSString *)songid{
    return [data objectForKey:@"songid"];
}

- (NSString *)content{
    return [data objectForKey:@"content"];
}

【问题讨论】:

  • 如果你使用cell.textLabel.text = ((MyClass *)self.data[indexPath.row]).name;而不是cell.textLabel.text = myclass.name;会发生同样的事情吗?
  • 你在-(NSString*)getName写了什么?
  • 是的,它仍在不断增加@MarkoNikolovski
  • 增加了多少?添加更多代码并确保您使用的是设备而不是模拟器进行分析。
  • @Tarek 我正在使用设备~ :) 并且在所有单元格显示一次之前它一直在增加

标签: ios uitableview memory


【解决方案1】:

似乎您的 myclass.name getter 返回一个新分配的对象。没有看到myclass,我们不能说更多。

【讨论】:

    猜你喜欢
    • 2017-03-24
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 2014-11-13
    • 2014-06-14
    • 2023-03-09
    相关资源
    最近更新 更多