So I have an object which represents a line drawn on the iPhone screen. I also have a ball moving around on the screen, and when the ball and the line intersect, the string is given a life. For my current build I am receiving this error constantly, with no crashes, but the ball stops moving on the screen:
2011-08-18 11:00:05.436 myProgram[192:5e03] * __NSAutoreleaseNoPool(): Object 0x1531c0 of class NSCFString autoreleased with no pool in place – just leaking
Line.h:
@interface Line : NSObject {
//time properties
NSTimeInterval life;
NSDate *startTime;
NSDate *currentTime;
}
//time properties
@property (nonatomic, retain) NSDate *startTime;
-(void) updateLife;
-(void) beginLifeTracking;
@end
Line.m
@synthesize startTime;
-(void)beginLifeTracking {
[self.startTime release]; //not sure if self is necessary here but startTime is released
//in case the same string is hit again
self.startTime = [NSDate date];
startTime = [NSDate dateWithTimeIntervalSince1970:0];
//NSLog(@"Time Interval: %f",startTime);
}
-(void) updateLife {
currentTime = [[NSDate date] retain];
NSLog(@"breakpoint1");
life = [currentTime timeIntervalSinceDate:self.startTime];
[currentTime release];
}
I’m assuming this is some sort of memory management error, but all my attempts to remedy it have failed. I’d really appreciate an explanation of what I’m doing wrong here. Thanks!
When you call
[self.startTime release], you’re over-releasing. It’s the job of the accessor (setStartTime:) to do this release.The code doesn’t make any sense, and is dangerous since it leaves a dangling ivar:
This should be:
The fact that you’re getting an autoreleasepool error suggests you’re running this on a background thread. Your code is not thread-safe, so that would be a problem.
EDIT Regarding threading code, how are you calling
beginLifeTracking? That would be where I would suspect you’re getting onto the wrong thread. I would be very concerned about this autoreleasepool warning.