【发布时间】:2011-12-27 17:17:48
【问题描述】:
要么我根本不懂 Instruments Leaks 工具,要么我快疯了。我已经在我的 iphone 应用程序上运行了该工具,它显示了一些泄漏。如果我理解正确,对于其中一个泄漏,它说它是由我的方法“writeHeading”分配的 NSDate 对象。分配对象的方法是:“dateWithTimeIntervalSinceReferenceDate:”。但是,我的 writeHeading 方法没有使用该方法。事实上,我的整个应用程序中的任何地方都没有使用该方法。
有人知道这里会发生什么吗?
这是writeHeading的代码:
- (void) writeHeading:(CLHeading *)heading
{
if (self.inFlight) {
[log writeHeading:heading];
} else {
IGC_Event *event = [[IGC_Event alloc] init];
event.code = 'K';
event.timestamp = heading.timestamp;
event.heading = heading;
[self addEvent:event];
[event release];
}
}
这是 Instruments 的截图:
这是 IGC_Event 的定义(根据多个响应者的要求):
@interface IGC_Event : NSObject {
int code;
CLLocation *location;
CLHeading *heading;
NSString *other;
NSDate *timestamp;
}
@property int code;
@property (nonatomic, retain) CLLocation *location;
@property (nonatomic, retain) CLHeading *heading;
@property (nonatomic, retain) NSString *other;
@property (nonatomic, retain) NSDate *timestamp;
@end
@implementation IGC_Event
@synthesize code;
@synthesize location;
@synthesize heading;
@synthesize other;
@synthesize timestamp;
@end
【问题讨论】:
-
IGC_Event 是否释放其 dealloc 方法中的时间戳和标题?
-
应该的。 IGC_Event 时间戳只是具有合成 getter 和 setter 的属性。我将在问题中添加 IGC_Event 的定义以明确说明
-
好的,但你是在 dealloc 中释放它们吗?请问可以包含dealloc方法吗?
-
现在问题中显示了完整的定义。 @synthesize 指令应生成具有正确释放调用的 dealloc 方法。你认为我应该添加一个空的dealloc吗?
-
不,dealloc 方法不是由@synthesize 生成的。所以有你的泄漏(实际上是 4 个潜在的泄漏)。我将其添加为答案
标签: ios xcode instruments memory-leaks