diff --git a/darwin/tab.m b/darwin/tab.m index 733864df..53e8c622 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -19,6 +19,7 @@ static void destroy(void *data) while ([t->tabview numberOfTabViewItems] != 0) [t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]]; // then destroy all the bins, destroying children in the process + // the above loop serves the purpose of binSetParent() [t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { NSValue *v = (NSValue *) obj; uiContainer *p; @@ -119,6 +120,7 @@ static void tabDeletePage(uiTab *tt, uintmax_t n) binSetMainControl(p, NULL); // remove the bin from the tab view + // this serves the purpose of binSetParent() i = [t->tabview tabViewItemAtIndex:n]; [t->tabview removeTabViewItem:i]; diff --git a/darwin/window.m b/darwin/window.m index 2cc53ebd..3e5749c1 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -59,8 +59,10 @@ static void windowDestroy(uiControl *c) // first hide ourselves [w->window orderOut:w->window]; // now destroy the bin - // the bin has no parent, so we can just call uiControlDestroy() - // we also don't have to worry about the NSWindow's reference to the content view; that'll be released too + // we need to remove the bin from its parent; this is equivalent to calling binSetParent() + // we do this by changing the content view to a dummy view + // the window will release its reference on the bin now, then it will release its reference on the dummy view when the window itself is finally released + [w->window setContentView:[[NSView alloc] initWithFrame:NSZeroRect]]; uiControlDestroy(uiControl(w->bin)); // now destroy the delegate [w->window setDelegate:nil];