【问题标题】:three20 TTTableSubtitleItem memory leak?three20 TTTableSubtitleItem 内存泄漏?
【发布时间】:2011-06-22 11:13:38
【问题描述】:

我创建了一个 TTTableSubtitleItem 并将其添加到一个数组中,将表数据源设置为该数组,然后释放该数组但是泄漏显示 TTTableSubtitleItem 上的泄漏我不知道为什么?

NSMutableArray *ar =  [[NSMutableArray alloc] init];
while (item = (NSDictionary*)[enumerator nextObject]) {
    NSString *result = [NSString stringWithFormat:@"tt://VideoListViewController/%@",
                        [item objectForKey:@"id"]];

    [ar addObject:[TTTableSubtitleItem itemWithText:[item objectForKey:@"name"]
                                           subtitle:[item objectForKey:@"description"]
                                                URL:result]];   

}
self.dataSource = [[myDataSource alloc] initWithItems:ar];
[ar release];

【问题讨论】:

    标签: iphone xcode memory-leaks three20


    【解决方案1】:

    您的泄漏点在:

    self.dataSource = [[myDataSource alloc] initWithItems:ar];
    

    改成:

    self.dataSource = [[[myDataSource alloc] initWithItems:ar] autorelease];
    

    您分配了 myDataSource 并没有释放它。另外,您能否在您的 .h 文件中向我展示您的“数据源”声明?

    【讨论】:

    • 嗨 Nayefc,正如您正确指出的那样,这正是问题所在。感谢您查看并帮助我解决此问题。我的头文件中没有 dataSource 声明,我需要将其放入吗?我正在使用 TTTableViewController,所以在我说 self.datasource 的代码中,这是对它的第一个引用。
    • 哦,好吧。不,你不需要把它。我只是以为你在你的 .h 文件中有它,因为你使用了“self”。我只是要求您提供它以确保您释放它以防您在@property 中使用“保留”。但别担心 - 你很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2013-01-20
    • 2011-10-31
    • 2019-08-10
    • 2013-06-24
    • 2011-03-22
    • 2015-04-20
    相关资源
    最近更新 更多