• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: simple question about variable retain/release (NSDate)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple question about variable retain/release (NSDate)


  • Subject: Re: simple question about variable retain/release (NSDate)
  • From: Andrew Farmer <email@hidden>
  • Date: Fri, 21 Nov 2008 18:30:05 -0800

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 (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


References: 
 >simple question about variable retain/release (NSDate) (From: Bob Sabiston <email@hidden>)

  • Prev by Date: simple question about variable retain/release (NSDate)
  • Next by Date: Re: CGPoint and CGRect
  • Previous by thread: simple question about variable retain/release (NSDate)
  • Next by thread: More instability in Distributed Objects used between multithreaded processes?
  • Index(es):
    • Date
    • Thread