fuz*_*oat 14 memory objective-c nslog dealloc
在类的dealloc方法中,如何为要解除分配的实例打印ID(或其他一些唯一标识符)?
- (void)dealloc {
NSLog(@"_deallocing: ??");
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?我只是想在控制台中获得更多反馈,以帮助学习.
非常感谢-gary-
dmk*_*ash 54
如果您特别想要对象的内存地址(如果您没有在您的类中实现,我认为可以将其视为"标识符"),您可以使用:
NSLog(@"deallocing %p", self);
Run Code Online (Sandbox Code Playgroud)
如果您有一个特定类的多个实例并且正在尝试确定何时获取dealloc,这可能会非常有用.
试试这个:
- (void)dealloc {
NSLog(@"_deallocing: %@", self);
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
这将向控制台输出有关该对象的更多信息.根据类,您将获得内存地址和类名称或更详细的内容.如果您想在自己的类中提供更详细的内容,请覆盖此方法并返回您想要的任何内容:
-(NSString *)description {
return @"Something useful about this object";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18589 次 |
| 最近记录: |