CALayer contents memory leak
CALayer contents memory leak
- Subject: CALayer contents memory leak
- From: Adam Fedor <email@hidden>
- Date: Sun, 02 Nov 2008 22:08:04 -0700
I have a simple program with a memory leak that is driving me crazy.
It's basically a slide show application (no I can't use IKSlideShow),
where I repeatedly set an image in a CALayer. When run, the app
increases in memory size by 10MB or so every time a new image is
displayed. I hate to post a lot of code, but my simple example is
literally 50 lines long, so I've put it at the end.
The very odd thing is that when the method used to set the image
(nextMedia:) is called from a user action (a button click, for
example), it works fine. No memory leak. Also, if I comment out the
"setContents:" line in the method, the memory leak goes away as well.
Nothing gets displayed of course, but this seems to indicate that
there is no memory leak in the code I wrote, but there is somehow a
leak in the CALayer code (but only when called via a NSTimer). I also
get the same results when compiled with automatic garbage collection.
===========
@implementation MyMediaView
- initWithFrame: (NSRect)frame
{
[super initWithFrame: frame];
[self setWantsLayer: YES];
rootLayer = [self layer];
currentDir = @"/Local/Pictures";
denum = [[[NSFileManager defaultManager] enumeratorAtPath:
currentDir] retain];
slideShowTimer = [NSTimer scheduledTimerWithTimeInterval: 20
target: self
selector:
@selector(stepSlideShow:)
userInfo: nil
repeats: YES];
[self nextMedia: self];
return self;
}
- (void) nextMedia: sender
{
NSString *next;
NSImage *image;
next = [denum nextObject];
if (next == nil)
{
[denum release];
denum = [[[NSFileManager defaultManager] enumeratorAtPath:
currentDir] retain];
next = [denum nextObject];
}
next = [currentDir stringByAppendingPathComponent: next];
image = [[NSImage alloc] initWithContentsOfFile: next];
if (image)
{
CGImageRef imageRef = NULL;
CGImageSourceRef sourceRef;
sourceRef = CGImageSourceCreateWithData((CFDataRef)[image
TIFFRepresentation], NULL);
if(sourceRef) {
imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
CFRelease(sourceRef);
}
[rootLayer setContents: (id)imageRef];
CGImageRelease(imageRef);
}
[image release];
}
- (void)stepSlideShow: (NSTimer *)aTimer
{
[self nextMedia: self];
}
@end
_______________________________________________
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