| Article: |
Animating Graphics in Cocoa, Part 1 | |
| Subject: | Memory leak | |
| Date: | 2003-08-22 15:18:45 | |
| From: | anonymous2 | |
|
Response to: Memory leak
|
||
| I'm not an expert, but I think this is not right. I tried it, and adding the release message makes everything crash after the loop ends. I think that dateWithTimeIntervalSince must be creating an already autoreleased object, no? | ||
Showing messages 1 through 2 of 2.
-
Memory leak
2005-07-29 18:28:09 valiantsoul [View]
Thats correct, watch NSCFDate in ObjectAlloc while the program is running - it gets called all the time but the peak amount of times an object of that type exists is 1 meaning no leak. -
Memory leak
2005-07-29 18:39:01 valiantsoul [View]
Oops sorry I forgot to watch CFDate and yes there is a memory leak.
Here is my modified animate: with no leak:
- (void)animate:(id)anObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDate *date = nil;
while (YES)
{
[self stepAnimation:nil];
[self setNeedsDisplay:YES];
if (date != nil)
[date release];
date = [NSDate dateWithTimeIntervalSinceNow:0.04];
[NSThread sleepUntilDate:date];
}
[pool release];
[NSThread exit];
}


