• 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: Strange Static Analyzer Warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange Static Analyzer Warning


  • Subject: Re: Strange Static Analyzer Warning
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 11 Dec 2013 10:48:13 -0600

On Dec 11, 2013, at 10:25 AM, Keary Suska wrote:

> In this method:
>
> - (void) drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView {
> if (self.state == NSOnState) {
>     // If selected we need to draw the border new background for selection (otherwise we will use default back color)
>     // Save current context
>     [[NSGraphicsContext currentContext] saveGraphicsState];
>
>     // Draw light vertical gradient
> 139     [kDMTabBarItemGradient drawInRect:frame angle:-90.0f];

> "Method returns an Objective-C object with a +1 retain count" (highlights kDMTabBarItemGradient)

Googling for kDMTabBarItemGradient finds this:
https://github.com/hetima/SafariStand/blob/master/DMTabBar/DMTabBarItem.m#L16

where that is a preprocessor macro defined as:
#define kDMTabBarItemGradient                               [[NSGradient alloc] initWithColors: [NSArray arrayWithObjects: \
                                                                                                         kDMTabBarItemGradientColor1, \
                                                                                                         kDMTabBarItemGradientColor2, \
                                                                                                         kDMTabBarItemGradientColor1, nil] \
                                                                                   atLocations: kDMTabBarItemGradientColor_Locations \
                                                                                    colorSpace: [NSColorSpace genericGrayColorSpace]]

That's horrible.  I'd avoid using this code.  An identifier prefixed with "k" is usually a constant.  Certainly, it shouldn't be an expression with side effects!

Anyway, right there is the allocated object that you're leaking.


>
>     // Draw shadow on the left border of the item
> 142     NSShadow *shadow = [[NSShadow alloc] init];

> "Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1" (highlights "NSShadow *shadow"

Do you have another "shadow" variable involved?  Perhaps an instance variable (although I would think the local would hide it)?

Could there be another horrible preprocessor macro that's making the "shadow" identifier into something strange?

What happens if you change all instances of "shadow" in this method to "localShadow" or something like that?

>     shadow.shadowOffset = NSMakeSize(1.0f, 0.0f);
>     shadow.shadowBlurRadius = 2.0f;
>     shadow.shadowColor = [NSColor darkGrayColor];
>     [shadow set];
>
>     [[NSColor blackColor] set];
>     CGFloat radius = 50.0;
>     NSPoint center = NSMakePoint(NSMinX(frame) - radius, NSMidY(frame));
>     NSBezierPath *path = [NSBezierPath bezierPath];
>     [path moveToPoint:center];
>     [path appendBezierPathWithArcWithCenter:center radius:radius startAngle:-90.0f endAngle:90.0f];
>     [path closePath];
>     [path fill];
>
>     // shadow of the right border
>     shadow.shadowOffset = NSMakeSize(-1.0f, 0.0f);
>     [shadow set];
>
>     center = NSMakePoint(NSMaxX(frame) + radius, NSMidY(frame));
>     path = [NSBezierPath bezierPath];
>     [path moveToPoint:center];
>     [path appendBezierPathWithArcWithCenter:center radius:radius startAngle:90.0f  endAngle:270.0f];
>     [path closePath];
>     [path fill];
>
>   [shadow release];
>
>     // Restore context
>     [[NSGraphicsContext currentContext] restoreGraphicsState];
> }
> }

Regards,
Ken


_______________________________________________

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


  • Follow-Ups:
    • Re: Strange Static Analyzer Warning
      • From: Keary Suska <email@hidden>
References: 
 >Strange Static Analyzer Warning (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: Threaded drawing
  • Next by Date: Re: Strange Static Analyzer Warning
  • Previous by thread: Strange Static Analyzer Warning
  • Next by thread: Re: Strange Static Analyzer Warning
  • Index(es):
    • Date
    • Thread