Do not autorelease global variables
This commit is contained in:
parent
2de7b338ad
commit
0c4e425872
1 changed files with 10 additions and 6 deletions
|
@ -56,10 +56,10 @@ Role kRolesMap[] = {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// Menu item is located for ease of removing it from the parent owner
|
// Menu item is located for ease of removing it from the parent owner
|
||||||
NSMenuItem* recentDocumentsMenuItem_;
|
NSMenuItem* recentDocumentsMenuItem_ = nil;
|
||||||
|
|
||||||
// TODO(sethlu): Doc & find a better naming
|
// TODO(sethlu): Doc & find a better naming
|
||||||
NSMenu* swapMenu_;
|
NSMenu* swapMenu_ = nil;
|
||||||
|
|
||||||
@implementation AtomMenuController
|
@implementation AtomMenuController
|
||||||
|
|
||||||
|
@ -97,10 +97,10 @@ NSMenu* swapMenu_;
|
||||||
|
|
||||||
if (!recentDocumentsMenuItem_) {
|
if (!recentDocumentsMenuItem_) {
|
||||||
// Locate & retain the recent documents menu item
|
// Locate & retain the recent documents menu item
|
||||||
recentDocumentsMenuItem_ = [[[[[[NSApp mainMenu]
|
recentDocumentsMenuItem_ = [[[[[NSApp mainMenu]
|
||||||
itemWithTitle:@"Electron"] submenu]
|
itemWithTitle:@"Electron"] submenu]
|
||||||
itemWithTitle:@"Open Recent"]
|
itemWithTitle:@"Open Recent"]
|
||||||
retain] autorelease];
|
retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
model_ = model;
|
model_ = model;
|
||||||
|
@ -169,16 +169,20 @@ NSMenu* swapMenu_;
|
||||||
// Swap back the submenu
|
// Swap back the submenu
|
||||||
[recentDocumentsMenuItem_ setSubmenu:swapMenu_];
|
[recentDocumentsMenuItem_ setSubmenu:swapMenu_];
|
||||||
|
|
||||||
|
// Release the previous swap menu if exists
|
||||||
|
if (swapMenu_) [swapMenu_ release];
|
||||||
// Retain the item's submenu for a future recovery
|
// Retain the item's submenu for a future recovery
|
||||||
swapMenu_ = [[[item submenu] retain] autorelease];
|
swapMenu_ = [[item submenu] retain];
|
||||||
|
|
||||||
// Repopulate with items from the submenu to be replaced
|
// Repopulate with items from the submenu to be replaced
|
||||||
[self moveMenuItems:swapMenu_ to:recentDocumentsMenu];
|
[self moveMenuItems:swapMenu_ to:recentDocumentsMenu];
|
||||||
// Replace submenu
|
// Replace submenu
|
||||||
[item setSubmenu:recentDocumentsMenu];
|
[item setSubmenu:recentDocumentsMenu];
|
||||||
|
|
||||||
|
// Release the previous menu
|
||||||
|
[recentDocumentsMenuItem_ release];
|
||||||
// Remember the new menu item that carries the recent documents menu
|
// Remember the new menu item that carries the recent documents menu
|
||||||
recentDocumentsMenuItem_ = [[item retain] autorelease];
|
recentDocumentsMenuItem_ = [item retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an item or a hierarchical menu to the item at the |index|,
|
// Adds an item or a hierarchical menu to the item at the |index|,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue