WebView: libdispatch leaks in an ARC-enabled app

2019-08-03 05:46发布

问题:

In a doc-based ARC-enabled application I have a WebView that is opening an HTML file. The idea is to do some editing, and then save to WebArchive. When I run Instruments I find random leaks as in the image below. I am not initializing anything with malloc, why am I getting them? (I get the leaks when I start opening and closing windows.)

Document.h

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface KBDocument : NSPersistentDocument {
    IBOutlet WebView *webView;
}

Document.m

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];

    NSString *urlStr = @"file:///Users/.........../Content/1/index.html";
    NSURL *url = [NSURL URLWithString:urlStr];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [[webView mainFrame] loadRequest:requestObj];
    [webView setEditable:YES];
}

Leaks:

回答1:

Well, you can see that the offending library is libdispatch; so it doesn't seems that your code is in error. Libdispatch http://libdispatch.macosforge.org/ is described here. You could check it out if you want to know more.