github/twui — pull request #127 by luosheng (2012-10-23 14:58:43+00:00)
Title: Fix TUINSView not being deallocated

This can be reproduced by following steps:

1. In `ExampleAppDelegate.m`, change
`[tableViewWindow setReleasedWhenClosed:FALSE]` to
`[tableViewWindow setReleasedWhenClosed:TRUE]`.
2. In `TUINSView.m`, add a breakpoint to the `dealloc` method.
3. Run the example, and close the table view window.

The breakpoint is expected to be hit, however it is not.

It seems to be a bug introduced by AppKit bridging, when the following line is invoked in the `setUp` method of `TUINSView`:

```objective-c
self.appKitHostView.layer.layoutManager = self;
```

The layer retains the layoutManager, which is the instance of TUINSView, and never has a chance to release it. And that's why the instance is not deallocated.

I fixed it by adding an observer to `NSWindowWillCloseNotification`, where I could set layer's layoutManager to `nil` to make the layer release the TUINSView's instance.