Networking in Cocoa
Subject:   about the dealloc and WindowWillClose
Date:   2003-05-30 10:15:46
From:   jeff_yecn
Great article! Thanks Mike!

I found that the dealloc message has never been sent. After some testing, I had figured out the reasons. It is a good example for cocoa memory management.

We send a release message to self in the windowWillClose method, hope to release self, but fail to do so. (You can add a NSLog in dealloc, and you will find output nothing).

The reason is our chatWindowController has been retained by the notificationcenter. SO, while we put our code of removing observer from notification center in the dealloc, we will never get there.

You should put the code:
[[NSNotificationCenter defaultCenter] removeObserver: self];
in windowWillClose: method, but not the dealloc.