Re: This code is leaking...
Re: This code is leaking...
- Subject: Re: This code is leaking...
- From: Mike Abdullah <email@hidden>
- Date: Sun, 19 Jun 2011 15:42:50 +0100
NEVER test for memory leaks using -retainCount. ALWAYS use the supplied tools instead.
On 19 Jun 2011, at 15:29, Tony Cate wrote:
> - (NSImage *)illustration
> {
> if ( illustrationData != nil ){
> NSImage* thisImage = [NSImage new];
You never (auto)release this image, so it's getting leaked
> NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] initWithData:illustrationData];
> NSPICTImageRep* pictImageRep = [[NSPICTImageRep alloc] initWithData:illustrationData];
>
> if ( bitmapImageRep != nil ){
> [thisImage addRepresentation:bitmapImageRep];
> [bitmapImageRep release];
> }
> if ( pictImageRep != nil ){
> [thisImage addRepresentation:pictImageRep];
> [pictImageRep release];
> }
You are correctly managing memory for the image reps. The image itself is your problem.
> return thisImage;
> }
> return nil;
> }
>
> The logs look like this:
>
> 2011-06-19 09:42:49.817 MyTestApp[92772:903] thisBitmapImageRep retainCount: 2
> 2011-06-19 09:42:49.820 MyTestApp[92772:903] thisBitmapImageRep retainCount: 3
> 2011-06-19 09:42:49.822 MyTestApp[92772:903] thisBitmapImageRep retainCount: 2
>
> bitmapImageRep is leaking. Why is the retain count 2 after the initWithData:? Should I file a bug?
>
> Tony
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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