I have a Cocoa app with an embedded WebView. I set the window controller as accessible through JavaScript with the code below.
The problem is that the call to setValue:self forKey:@"console" seems to introduce a memory leak under ARC in a sense that the WebView and window controller are never released after the window was closed.
When I comment out the setValue line the WebView and controller are automatically released when the window is closed.
I tried [self.webView.windowScriptObject removeWebScriptKey:@"console"], but that did not work either.
Code to add the JavaScript object in the window controller:
- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject
forFrame:(WebFrame *)frame {
if (frame != self.webView.mainFrame) return;
[self.webView.windowScriptObject setValue:self forKey:WELCOME_WINDOW_JS_NAME];
}
Mark,
You have identified the problem code. What is missing is that you aren't setting the key to nil when you release the window: setValue: nil forKey: @"console". Do that and all will be well.
Andrew
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With