Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3233950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:20:09+00:00 2026-05-17T17:20:09+00:00

I know this is a long-shot, but since I need this code to work,

  • 0

I know this is a long-shot, but since I need this code to work, maybe someone here can help.

I’m using the Irregularly Shaped Buttons code from CodeProject.com in one of my iPhone apps. Works great, but Instruments is reporting two memory leaks. I’m using the code in a standard UIViewController, but that is inside a UINavigationController, which might be where the problems lie.

The first leak is reported in the myInit method of clickThruButton.m

- (void) myInit
{
    // Set so that any alpha > 0x00 (transparent) sinks the click
    uint8_t threshold = 0x00;
    self.alphaMask = [[AlphaMask alloc]  initWithThreshold: threshold]; 
    [self setMask];
}

I can see the release down below, so I’m not sure why this would leak:

- (void)dealloc
{
    [self.alphaMask release];
    [super dealloc];
}

Perhaps we first need to check to see if self.alphaMast is nil before doing the alloc?

The second is at the end of the calcHitGridFromCGImage method in AlphaMask.m:

// COPIES buffer
// is AUTORELEASED!
// http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/
// MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH
NSData* ret = [NSData dataWithBytes: (const void *) dest 
                             length: (NSUInteger) destBytes ];

CGContextRelease (alphaContext);
free (alphaGrid);
free (dest);

return ret;

The leak appears on the NSData assignment. There’s no alloc, new or copy, so where’s the leak?

I would REALLY appreciate any help you could provide here. I know it’s a stretch, but I need this to work ASAP. Thanks!

UPDATED:

The full source can be found at the link above, but this may help clear up the alphaMask definition:

//
//  ClickThruButton.h
//  Test
//
//  Pi

@class AlphaMask;

@interface clickThruButton : UIButton 
{
    @private AlphaMask* _alphaMask;
}

@end

and…

//
//  ClickThruButton.m
//  Test
//
//  Pi

#import "clickThruButton.h"
#import "AlphaMask.h"

@interface clickThruButton ()

@property (nonatomic, retain) AlphaMask* alphaMask;

- (void) myInit;
- (void) setMask;

@end

@implementation clickThruButton

@synthesize alphaMask = _alphaMask;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:20:09+00:00Added an answer on May 17, 2026 at 5:20 pm

    (1)

    The alphaMask property is likely set to -retain. This causes the retain count to increase by 1 automatically when set. But [AlphaMask alloc] already returns an object with retain count of +1, so the overall retain count is excessively +2.

    The [self.alphaMask release] later can only decrease the retain count by 1, so finally the count cannot get to 0 and deallocate, i.e. the memory will be leaked.

    You should rewrite that as

    AlphaMask* mask = [[AlphaMask alloc]  initWithThreshold: threshold];
    self.alphaMask = mask;
    [mask release];        // cancel the retain.
    

    (2)

    I don’t think there’s any leak in this piece of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a long shot - but is there any way at
I know this one is going to be a long-shot, but I thought I'd
I know this is a long shot but is there any way of getting
This is a long-shot but does anyone know of a library in Java/C# for
I know this is a long shot, but does anyone know of a dataset
This is a long shot but I've seen things which might make it posssible.
OK, I know this is a long shot: Does HTTP offer a way to
I know this looks a bit long but i tried to explain the problem
I know this might be a no-brainer, but please read on. I also know
I know this isn't strictly a programming question but y'all must have experienced this.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.