• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: This code is leaking...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >This code is leaking... (From: Tony Cate <email@hidden>)

  • Prev by Date: Re: How to redraw a view in slow-motion
  • Next by Date: Re: Non-rectangular image of NSView for dragging
  • Previous by thread: This code is leaking...
  • Next by thread: Re: This code is leaking...
  • Index(es):
    • Date
    • Thread