有一个我从未遇到过的奇怪问题
有一个 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"];
}