From: David Elliott Date: Thu, 14 Feb 2008 19:46:21 +0000 (+0000) Subject: More GC fixes. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1a393573c347d44aac5ca999ed52ff7bf435999f More GC fixes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51795 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/cocoa/NSMenu.mm b/src/cocoa/NSMenu.mm index 635b2ee96e..c59ee77a0a 100644 --- a/src/cocoa/NSMenu.mm +++ b/src/cocoa/NSMenu.mm @@ -15,6 +15,7 @@ #include "wx/log.h" #endif // WX_PRECOMP +#include "wx/cocoa/ObjcRef.h" #include "wx/cocoa/NSMenu.h" #import @@ -97,7 +98,10 @@ WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject) // ======================================================================== 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 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) { diff --git a/src/cocoa/listbox.mm b/src/cocoa/listbox.mm index 13ca565a90..f0a3a0c195 100644 --- a/src/cocoa/listbox.mm +++ b/src/cocoa/listbox.mm @@ -22,6 +22,7 @@ #include "wx/cocoa/string.h" #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/ObjcRef.h" #include "wx/cocoa/NSTableDataSource.h" #import @@ -83,7 +84,7 @@ The listbox contents are sorted in alphabetical order. 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])]; @@ -129,7 +130,8 @@ wxListBox::~wxListBox() { [GetNSTableView() setDataSource: nil]; [m_cocoaDataSource release]; - [m_cocoaItems release]; + wxGCSafeRelease(m_cocoaItems); + m_cocoaItems = nil; DisassociateNSTableView(GetNSTableView()); }