Re: Problems with setImage
Re: Problems with setImage
- Subject: Re: Problems with setImage
- From: Quincey Morris <email@hidden>
- Date: Sun, 06 Mar 2011 00:38:44 -0800
On Mar 6, 2011, at 00:19, Benedikt Iltisberger wrote:
> NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];
> NSImage *image = [[NSImage alloc] init];
> [image addRepresentation:bitmapRep];
> [bitmapRep release];
>
> LEAK -> [myButton setImage:image];
>
> [image release];
>
> I call this every second to update a picture. Everytime I call this the memory usage increases by 1MB until the memory is full.
Why do you think the leak occurs at this line? The memory management of 'myButton', 'bitmapRep' and 'image' looks correct. It seems more likely the leak is from 'cgImage' -- where do you CFRelease that?
The easy way to solve this is to use Instruments (in Xcode, Run->Run with Performance Tool->Allocations). Then look for 1MB allocations piling up and see where they're being created. Or use Heapshot to isolate the repeated allocations.
> Ok the Outlet is retained but shouldn't cocoa use the same space in memory over and over again instead of allocating new space every second?
The only outlet here is 'myButton', and it is *not* being re-created every second. A new 'image' is created every second, and that's a new object every time (along with a new 'bitmapRep', and (presumably) a new 'cgImage'.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden