Re: NSDate autorelease problem
Re: NSDate autorelease problem
- Subject: Re: NSDate autorelease problem
- From: j o a r <email@hidden>
- Date: Wed, 3 Sep 2008 10:19:51 -0700
On Sep 3, 2008, at 10:02 AM, email@hidden wrote:
I'm trying to calculate the elapsed time by calling this twice and
getting the difference.
double Seconds()
{
return [[NSDate date] timeIntervalSince1970];
}
How about replacing that with:
return [NSDate timeIntervalSinceReferenceDate];
That said, I would bet that there are simple C APIs that would be more
efficient to use for this purpose.
This is being called from an audio play back proc which is being
called about 100 times a second. I'm getting this error message in
the log window a whole bunch of times.
2008-09-03 09:39:30.766 App[321] *** _NSAutoreleaseNoPool(): Object
0x36acd0 of class NSCFDate autoreleased with no pool in place - just
leaking
The reason is that you're executing the code above on a non-main
thread. See the documentation for NSAutoReleasePool for details (or
just use Google), but in general:
"Cocoa expects there to be an autorelease pool always available. If a
pool is not available, autoreleased objects do not get released and
you leak memory. NSAutoreleasePool objects are automatically created
and destroyed in the main thread of applications based on the
Application Kit, so your code normally does not have to deal with them."
On threads that you set up, you have to manage the top level
autorelease pool manually.
j o a r
_______________________________________________
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