summaryrefslogtreecommitdiff
path: root/macosx/RecentItemsMenu.m
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-29 19:16:02 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-01-29 19:16:02 +0000
commit3e3a841cee601493af68af50c350c1d375701230 (patch)
treec332c6f461a3dc0869e9c46fa462a26ea343bd56 /macosx/RecentItemsMenu.m
parent5c466700361ce360fd19bbc87e2cf7d90311669c (diff)
downloadpcsxr-3e3a841cee601493af68af50c350c1d375701230.tar.gz
fixed a memory leak in non-ARC code.
When we fail, autorelease, not just release self. Change createMenuItem: to newMenuItem: this makes ARC know we are returning a non-autoreleased object. It's bad practice to remove items from the array we're iterating over. the itemArray call might keep a local copy, but it still makes me cringe. Create an autorelease pool around plug-in initialization code. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@82589 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/RecentItemsMenu.m')
-rwxr-xr-xmacosx/RecentItemsMenu.m26
1 files changed, 15 insertions, 11 deletions
diff --git a/macosx/RecentItemsMenu.m b/macosx/RecentItemsMenu.m
index 136895c2..357ebd65 100755
--- a/macosx/RecentItemsMenu.m
+++ b/macosx/RecentItemsMenu.m
@@ -20,8 +20,8 @@
// Populate the menu
NSArray* recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
NSInteger index = 0;
- for(NSURL* url in recentDocuments) {
- NSMenuItem *tempItem = [self createMenuItem:url];
+ for (NSURL* url in recentDocuments) {
+ NSMenuItem *tempItem = [self newMenuItem:url];
[self addMenuItem:tempItem atIndex:index];
RELEASEOBJ(tempItem);
index++;
@@ -33,12 +33,12 @@
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:documentURL];
NSMenuItem* item = RETAINOBJ([self findMenuItemByURL:documentURL]);
- if(item != nil) {
+ if (item != nil) {
[self removeItem:item];
[self insertItem:item atIndex:0];
RELEASEOBJ(item);
} else {
- NSMenuItem *newitem = [self createMenuItem:documentURL];
+ NSMenuItem *newitem = [self newMenuItem:documentURL];
[self addMenuItem:newitem];
RELEASEOBJ(newitem);
}
@@ -50,7 +50,7 @@
// Prevent menu from overflowing; the -2 accounts for the "Clear..." and the separator items
NSInteger maxNumItems = [[NSDocumentController sharedDocumentController] maximumRecentDocumentCount];
- if(([self numberOfItems]-2) > maxNumItems) {
+ if (([self numberOfItems] - 2) > maxNumItems) {
[self removeItemAtIndex:maxNumItems];
}
}
@@ -71,7 +71,7 @@
[self insertItem:item atIndex:index]; // insert at the top
}
-- (NSMenuItem*)createMenuItem:(NSURL*)documentURL
+- (NSMenuItem*)newMenuItem:(NSURL*)documentURL
{
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:[documentURL lastPathComponent] action:@selector(openRecentItem:) keyEquivalent:@""];
[newItem setRepresentedObject:documentURL];
@@ -97,11 +97,15 @@
// Document items are menu items with tag 0
- (void)removeDocumentItems
{
- for(NSMenuItem* item in [self itemArray]) {
- if([item tag] == 0) {
- [self removeItem:item];
- }
- }
+ NSMutableArray *removeItemsArray = [NSMutableArray array];
+ for (NSMenuItem* item in [self itemArray]) {
+ if([item tag] == 0) {
+ [removeItemsArray addObject:item];
+ }
+ }
+ for (NSMenuItem *item in removeItemsArray) {
+ [self removeItem:item];
+ }
}
@end