菜鸟教程小白 发表于 2022-12-11 20:29:32

ios - Instruments Leaks 显示不存在的方法调用


                                            <p><p>要么我根本不懂 Instruments Leaks 工具,要么我快疯了。我已经在我的 iphone 应用程序上运行了该工具,它显示了一些泄漏。如果我理解正确,对于其中一个泄漏,它说它是由我的方法“writeHeading”分配的 NSDate 对象。分配对象的方法是:“dateWithTimeIntervalSinceReferenceDate:”。但是,我的 writeHeading 方法没有使用该方法。事实上,我的整个应用程序中的任何地方都没有使用该方法。 </p>

<p>有人知道这里会发生什么吗?</p>

<p>这是writeHeading的代码:</p>

<pre><code>- (void) writeHeading:(CLHeading *)heading
{
    if (self.inFlight) {
      ;
    } else {
      IGC_Event *event = [ init];
      event.code = &#39;K&#39;;
      event.timestamp = heading.timestamp;   
      event.heading = heading;
      ;
      ;
    }
}
</code></pre>

<p>这是 Instruments 的截图:
<img src="/image/YaIrg.png" alt="enter image description here"/> </p>

<p>这是 IGC_Event 的定义(根据多个响应者的要求):</p>

<pre><code>@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
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>假设没有 ARC,您需要确保 IGC_Event 对象释放其时间戳和其他可能已保留或复制的引用。</p>

<p>所以在 IGC_Event 中你需要一个这样的 dealloc:</p>

<pre><code>- (void) dealloc {

    ;
    ;
    ;
    ;


    ;
}
</code></pre>

<p>Leaks 只是告诉您该时间戳对象是在哪里创建的,而不是您应该在哪里发布它。</p>

<p>当然,这可能不是您唯一泄漏的地方,但那里有 4 个潜在的泄漏点。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Instruments Leaks 显示不存在的方法调用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8106247/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8106247/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Instruments Leaks 显示不存在的方法调用