感謝您的解決方案。它效果很好。事實上不是描述懷特洛克萊是泄漏的原因,但我自己的記憶規則實施(是1年前:()。奇怪的是,儀器指出,該方法調用....看看我的班現在看起來如何:
@implementation EventItem
@synthesize eventString, detailsString, date;
-(id)initEvent:(NSString*)eventStr details:(NSString*)detailsStr{
if((self = [super init])){
self.eventString = [[NSMutableString alloc] initWithString:eventStr];
self.detailsString = [[NSString alloc] initWithString:detailsStr];
self.date =[[NSMutableString alloc] init];
NSDate* currentDate = [NSDate date];
NSString *dateDescStr = [currentDate descriptionWithLocale:[NSLocale systemLocale]];
[date appendString:dateDescStr];
[eventString release];
[detailsString release];
[date release];
}
return self;
}
-(NSMutableDictionary*)eventDictionary{
if(!dictionary)
dictionary = [[NSMutableDictionary alloc] init];
else
return dictionary;
[dictionary setObject:self.date forKey:@"Event"];
[dictionary setObject:self.date forKey:@"Date"];
[dictionary setObject:self.detailsString forKey:@"Details"];
[dictionary setObject:self.eventString forKey:@"EventDescription"];
return [dictionary autorelease];
}
-(void)dealloc{
// NSLog(@"dealloc called in EventItem");
[eventString release];
[detailsString release];
[date release];
[super dealloc];
}
@end
現在
,即我還有一個問題是關於經由加載某些圖像 「loadWithContentsOfFile:」
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = OC_CELL_HEIGHT;
self.tableView.backgroundColor = [UIColor clearColor];
UIImage* backgroundImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TableBg" ofType:@"png"]];
UIImageView* background = [[UIImageView alloc] initWithFrame:self.tableView.frame];
background.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
background.image = backgroundImage;
[background sizeToFit];
[backgroundImage release];
[self.tableView setBackgroundView:background];
[background release];
[self.tableView setAutoresizesSubviews:YES];
selectedOCData = nil;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
}
線:
UIImage* backgroundImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TableBg" ofType:@"png"]];
泄漏98%,haviest回溯是240 kb。我爲此附上了一個屏幕截圖。有沒有問題與實際調用initWithContentsOfFile,但與tableView是不是正確解除分配?(我的類是一個tableViewController)。
謝謝, 亞歷克斯。 ![instruments](https://i.stack.imgur.com/enhwj.png)
從代碼中很難判斷,但看起來基本正確。由於您將'tableView'視爲類屬性,因此請確保您在'dealloc'方法中釋放'tableView'。 如果您需要更深入的幫助,我會建議開始一個新問題。 – Kongress