]> git.saurik.com Git - wxWidgets.git/commitdiff
More GC fixes.
authorDavid Elliott <dfe@tgwbd.org>
Thu, 14 Feb 2008 19:46:21 +0000 (19:46 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 14 Feb 2008 19:46:21 +0000 (19:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51795 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/cocoa/NSMenu.mm
src/cocoa/listbox.mm

index 635b2ee96eef23eca7cc52aa3974ddfb44364e3b..c59ee77a0a815654aee2123e51bef768b807e5b9 100644 (file)
@@ -15,6 +15,7 @@
     #include "wx/log.h"
 #endif // WX_PRECOMP
 
+#include "wx/cocoa/ObjcRef.h"
 #include "wx/cocoa/NSMenu.h"
 
 #import <Foundation/NSNotification.h>
@@ -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<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)
 {
index 13ca565a905300fbddc363f70a2c1b15fa3f07c1..f0a3a0c19589b2e4dc01bed43cef1179e18ea6b6 100644 (file)
@@ -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 <Foundation/NSArray.h>
@@ -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());
 }