On 21 Nov 08, at 18:17, Bob Sabiston wrote:
Hi,

I have a newbie question about retain/release stuff when using NSDate. I am confused a little about what is necessary in this case.

I've got a local variable sTime (NSDate *). I use it to measure the time and then compare it to the current time, so that I can space out an
animation over one second.

The docs say that [NSDate date] creates and returns an NSDate. Does that mean the memory's been allocated until I release it?

See the Cocoa memory management rules:

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html

As the selector name "date" doesn't start with "alloc" or "new", and doesn't contain "copy", you don't own this object, making all the releases on sTime incorrect. The crashes are occurring when the enclosing NSAutoreleasePool gets purged (but that's an implementation detail - the part that matters is that you're releasing objects that you never owned).

Here's what I have.  It works until the very end, where it crashes.
...

                // now wait for 1/30th of a second
                do {
                   elapsedTime = -[sTime timeIntervalSinceNow];
                }
                while (elapsedTime < frameduration);

This is incredibly inefficient. Use

[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:frameduration]]

instead. (But realize that this'll run slightly under 30 FPS, as the drawing takes some time.)
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to