On Wednesday, July 16, 2003, at 10:52 AM, Matthew T. Russotto wrote:
It looks to me like there's a retain loop in the WebKit. Suppose I'm
rendering a webView in some off-screen window:
webWin = [[NSWindow alloc] initWithContentRect: webFrameRect
styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered
defer:NO screen: [NSScreen mainScreen]];
// webWin retain count is now 1
webView = [[WebView alloc] initWithFrame: webFrameRect ];
// webView retain count is now 1
[[webWin contentView] addSubview: webView];
// webView retain count is now 2
[webView setHostWindow: webWin];
// webWin retain count is now 2
[webWin close]
// webWin retain count is now 1
[webView release]
// webView retain count is now 1. And we're stuck.
The easy workaround is to [webView setHostWindow nil] before
releasing, but am I doing something wrong or is this a bug?
You need to do the setHostWindow before releasing. The WebView does
retain the host window, and if you call setHostWindow: you need to be
sure to call setHostWindow:nil when closing the window, otherwise you
have a retain loop.
Note that you don't need to call setHostWindow: at all if the view is
going to always be in the window. The setHostWindow: method is there
for use in those rare cases where a WebView needs to be removed from
the window and the returned to the window later (as in Safari's tabbed
browsing implementation).
Having to worry about this is a bit inconvenient. It's debatable
whether this is a bug or not. One alternative design is to not retain
the host window, which would avoid this particular retain loop. But
that creates the possibility of a dangling object reference; you'd
still have to be sure to call setHostWindow:nil at the same time,
although the symptom would be some kind of random behavior rather than
a leak.
-- Darin
_______________________________________________
webkitsdk-dev mailing list | email@hidden
Help/Unsubscribe: http://www.lists.apple.com/mailman/listinfo/webkitsdk-dev
Do not post admin requests to the list. They will be ignored.
References:
>(no subject) (From: "Matthew T. Russotto" <email@hidden>)