在我自己的类中重写保留和释放方法

发布于 2025-01-03 12:14:14 字数 67 浏览 0 评论 0原文

我想重写类 MapsLocationView 中的保留和释放方法,以便了解我在哪里获得额外的释放。请帮助我以正确的方式做

I want to override a retain and release methods in my class MapsLocationView in order to understand where i'm getting an extra release. Please help me do it in proper way

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2025-01-10 12:14:14

这只是做你在 Objective-C 中其他地方所做的事情的一个例子。

- (oneway void)release;
{
    [super release];
}

- (id)retain;
{
    return [super retain];
}

It's just a case of doing what you do everywhere else in Objective-C.

- (oneway void)release;
{
    [super release];
}

- (id)retain;
{
    return [super retain];
}
池予 2025-01-10 12:14:14

对我来说,进行释放保留调查的最佳方法是:

'MapsLocationView.h'
@interface MapsLocationView : UIView {
    int releaseCount;
}

'MapsLocationView.m'
- (void)awakeFromNib {
    releaseCount = 0;
}

-(id)retain {
    NSLog(@"retain count+++:%d", [self retainCount]);
    return [super retain];
}

- (oneway void)release {
    releaseCount++;
    NSLog(@"releaseCount---:%d", releaseCount);
    [super release];
}

我还发现,如果您用鼠标右键单击该方法,您可以跳转到其定义:)

The best way to do release-retain investigation for me was:

'MapsLocationView.h'
@interface MapsLocationView : UIView {
    int releaseCount;
}

'MapsLocationView.m'
- (void)awakeFromNib {
    releaseCount = 0;
}

-(id)retain {
    NSLog(@"retain count+++:%d", [self retainCount]);
    return [super retain];
}

- (oneway void)release {
    releaseCount++;
    NSLog(@"releaseCount---:%d", releaseCount);
    [super release];
}

I also found that if you click on the method by right mouse button you can jump to its definition :)

り繁华旳梦境 2025-01-10 12:14:14

这不是正确的方法,您应该使用泄漏工具或代码分析器来查找额外释放的来源

this would not be the proper way, you should use the leaks instrument or code analyser to find where the extra release is coming from

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文