Re: NSImage allocation issues
Re: NSImage allocation issues
- Subject: Re: NSImage allocation issues
- From: Jeremy Dronfield <email@hidden>
- Date: Fri, 30 Apr 2004 14:32:50 +0100
Sending your image an -autorelease is crashing your app because the
image was never retained. Your leak, I presume, is caused by your menu
item, which according to the posted code, doesn't get released after
you add it to the menu. Try:
[menu addItem:mi];
[mi release];
Regards,
-Jeremy
On 30 Apr 2004, at 12:41 pm, Jesus De Meyer wrote:
Hi,
I just found a big memory leak in my application. Let me explain. I use
a menu that shows small icons and one of its submenus receives the icon
from files (via NSWorkspace). Now I've seen that in my iteration
process the images remain allocated. I have tried sending them the
autorelease message but that didn't work, it made my app crash.
This is what I currently do:
NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle:theItem action:nil
keyEquivalent:@""];
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:itemPath];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"showIcons"]
intValue] && icon) {
[icon setSize:NSMakeSize(16, 16)];
[mi setImage:icon];
}
[menu addItem:mi];
Anybody know how I can fix this?
Thanks in advance
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.