I've had to do some drawing lately. I've been working with Core Graphics and think I know my way around.
I keep getting this memory leak that's driving me nuts. I have no idea what's happening. It's happening whenever I draw a gradient. Has anyone else seen this?
I didn't have too much experience managing memory with Core Foundation -- I've made some pretty air-tight Cocoa apps, though. I've tried everything I can think of and this leak is still here. Any ideas?
I create a CustomView that is also the Application Delegate. Here is the entire code that I am running:
When I comment out the *** line, the memory leak goes away.
Any ideas?
I keep getting this memory leak that's driving me nuts. I have no idea what's happening. It's happening whenever I draw a gradient. Has anyone else seen this?
I didn't have too much experience managing memory with Core Foundation -- I've made some pretty air-tight Cocoa apps, though. I've tried everything I can think of and this leak is still here. Any ideas?
I create a CustomView that is also the Application Delegate. Here is the entire code that I am running:
Code:
@interface CustomView: NSView
@end
@implementation CustomView
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSWindow *newWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 256, 512) styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing: NSBackingStoreBuffered defer: NO];
CustomView *newCustomView = [[CustomView alloc] initWithFrame: [[newWindow contentView] bounds]];
[newWindow setContentView: newCustomView];
[newCustomView release];
[newWindow makeKeyAndOrderFront: nil];
}
- (void)drawRect:(NSRect)rect
{
CGContextRef currentContext = [[NSGraphicsContext currentContext] graphicsPort];
CGColorSpaceRef newColorSpace = CGColorSpaceCreateDeviceGray();
CGFloat components[4] = { 1 , 1 , 0 , 1 };
CGGradientRef newGradient = CGGradientCreateWithColorComponents(newColorSpace, components, NULL, 2);
CGColorSpaceRelease(newColorSpace);
*** CGContextDrawLinearGradient(currentContext, newGradient, CGPointZero, CGPointMake(0, rect.size.height), 0);
CGGradientRelease(newGradient);
}
@end
When I comment out the *** line, the memory leak goes away.
Any ideas?