#include "wx/log.h"
#endif // WX_PRECOMP
+#include "wx/cocoa/ObjcRef.h"
#include "wx/cocoa/NSMenu.h"
#import <Foundation/NSNotification.h>
// ========================================================================
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSMenu)
-struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = [[WX_GET_OBJC_CLASS(wxNSMenuNotificationObserver) alloc] init];
+// New CF-retained observer (this should have been using wxObjcAutoRefFromAlloc to begin with)
+static wxObjcAutoRefFromAlloc<wxNSMenuNotificationObserver*> s_cocoaNSMenuObserver([[WX_GET_OBJC_CLASS(wxNSMenuNotificationObserver) alloc] init]);
+// For compatibility with old code
+struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = s_cocoaNSMenuObserver;
void wxCocoaNSMenu::AssociateNSMenu(WX_NSMenu cocoaNSMenu, unsigned int flags)
{
#include "wx/cocoa/string.h"
#include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/ObjcRef.h"
#include "wx/cocoa/NSTableDataSource.h"
#import <Foundation/NSArray.h>
return false;
// Provide the data
- m_cocoaItems = [[NSMutableArray arrayWithCapacity:n] retain];
+ m_cocoaItems = wxGCSafeRetain([NSMutableArray arrayWithCapacity:n]);
for(int i=0; i < n; i++)
{
[m_cocoaItems addObject: wxNSStringWithWxString(choices[i])];
{
[GetNSTableView() setDataSource: nil];
[m_cocoaDataSource release];
- [m_cocoaItems release];
+ wxGCSafeRelease(m_cocoaItems);
+ m_cocoaItems = nil;
DisassociateNSTableView(GetNSTableView());
}