• 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: NSSound & autorelease
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSound & autorelease


  • Subject: Re: NSSound & autorelease
  • From: Daniel Jalkut <email@hidden>
  • Date: Sat, 21 Jun 2003 10:59:20 -0700

I think you're wise to be concerned about this, but you should rest assured that things are "OK" unless you have seen evidence to believe otherwise.

The contract with the API is that you will take responsibility for releasing objects you allocate, and that you will not send messages to objects that been released.

When you send the play message to the NSSound - it's still allocated, so no crime there. When your autorelease pool releases it, it's the NSSound object's responsibility to do whatever it deems appropriate to dispose itself safely. This may mean stopping the playback short and disposing itself, or it may mean it has a contract with another object to perform the playback in a safe, self-disposing way. Probably in most cases, the underlying playback code has already received a reference to a sound buffer that it's going to play over the next few fractions of a second, so it's no big deal to release the NSSound "proxy" to the sound.

In any case, the 2 possible negative outcomes are:

1. Crash! In this case, it's a bug in NSSound and Apple should get a bug about it. It needs to make sure it conforms to the contract. It cannot require you to be this concerned about the situation.

2. Sound playback is cut short. This is probably an argument for your doing something to retain the object until the sound is no longer playing. I don't think Apple is in the business of self-perpetuating object lives for the sake of user-friendliness.

Daniel

On Saturday, June 21, 2003, at 09:57 AM, Chris Silverberg wrote:

Hello list,

A question... I've seen several developers doing this to play a sound:

[[NSSound soundNamed: @"YouHaveNewMail"] play];

So, is this really safe? NSSound returns an autoreleased instance of a
sound... and 'play' plays the sound asynchronously. What happens if this
sound is playing and the autorelease pool releases its objects?

Now, I could see that this would not be a problem if NSSound did a
self-retain when you call play... and it did a self-release when the sound
completed. But without documentation, I can't just assume that. Does
anyone know the real deal?

thanks much,
Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSSound & autorelease (From: Chris Silverberg <email@hidden>)

  • Prev by Date: memory usage monitoring
  • Next by Date: Re: Advice for Web front end
  • Previous by thread: NSSound & autorelease
  • Next by thread: memory usage monitoring
  • Index(es):
    • Date
    • Thread