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;