当 UITableView 滚动时,内存不断增加



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

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

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

但是当更换

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;
}

我的类

有两个类一个基础另一个继承

基础:

@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"];
}

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

最新更新