My document subclass retains a reference to an object representing the data 
model. When the document is dealloc'ed, the DM object is released.

One of my app's main menus has dynamic content built from the DM found in the 
current document. This is done by setting the app delegate to also be the 
menu's delegate, and populating the menu using 
-menu:updateItem:atIndex:shouldCancel: which gets DM information from the 
current document.

A menu item can set the DM as its represented object, therefore also retaining 
it.

When the document is closed and dealloced, the DM is not always dealloced 
because the menu item will still be retaining it. The dealloc can be triggered 
by forcing a menu update (e.g. click in the menu bar) which updates the menu, 
finds the old document gone and so repopulates the menu.

The fact that the menu holds on to the DM after its document has gone wouldn't 
really matter too much, except that it's possible for the stale DM to cause 
problems during a subsequent file load. This is to do with it subscribing to 
certain notifications that can be triggered during a load, and when handling 
these notifications, referring to the (now long gone, and hence stale) document 
instance.

I've fixed this particular problem, but I feel it would be better if at doc 
close/dealloc time, I could force a clear out of the menu's represented 
objects, so that the DM dealloc is never deferred until later. So my question 
is, is there a straightforward way to force a given (main) menu to release its 
represented objects at that time?

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to