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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to