FROM : James Hober
DATE : Tue Mar 25 23:19:17 2008
On Mar 25, 2008, at 9:44 AM, j o a r wrote:
> I wouldn't recommend doing that. I'd suggest using something like
> this:
>
> - (void) dealloc
> {
> NSAssert(FALSE, @"Singleton objects should never be released");
> [super dealloc];
> }
>
> This communicates better what your intention is, and also catches
> the unlikely case of this instance ever being deallocated when it
> shouldn't, or if the class is being repurposed to a multi-instance
> pattern.
I appreciate your suggestion. It's generally good defensive
programming to build in warnings to yourself when code that you do
not expect to execute actually gets executed.
On the other hand, the documentation for dealloc says:
"Note that when an application terminates, objects may not be sent a
dealloc message since the process’s memory is automatically cleared
on exit—it is more efficient simply to allow the operating system to
clean up resources than to invoke all the memory management methods."
Since it says "may," theoretically it could be considered an
implementation detail that dealloc is not called during termination
and Apple could change things in a future release. Admittedly, this
is not very likely and admittedly worrying about code that almost
certainly will never execute is probably not the best use of time.
And yet it is very common to have a number of singleton objects of
this kind in Cocoa apps. So nearly all of us are "solving" this one
way or another.
James_______________________________________________
Cocoa-dev mailing list (<email_removed>)
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/<email_removed>
This email sent to <email_removed>
DATE : Tue Mar 25 23:19:17 2008
On Mar 25, 2008, at 9:44 AM, j o a r wrote:
> I wouldn't recommend doing that. I'd suggest using something like
> this:
>
> - (void) dealloc
> {
> NSAssert(FALSE, @"Singleton objects should never be released");
> [super dealloc];
> }
>
> This communicates better what your intention is, and also catches
> the unlikely case of this instance ever being deallocated when it
> shouldn't, or if the class is being repurposed to a multi-instance
> pattern.
I appreciate your suggestion. It's generally good defensive
programming to build in warnings to yourself when code that you do
not expect to execute actually gets executed.
On the other hand, the documentation for dealloc says:
"Note that when an application terminates, objects may not be sent a
dealloc message since the process’s memory is automatically cleared
on exit—it is more efficient simply to allow the operating system to
clean up resources than to invoke all the memory management methods."
Since it says "may," theoretically it could be considered an
implementation detail that dealloc is not called during termination
and Apple could change things in a future release. Admittedly, this
is not very likely and admittedly worrying about code that almost
certainly will never execute is probably not the best use of time.
And yet it is very common to have a number of singleton objects of
this kind in Cocoa apps. So nearly all of us are "solving" this one
way or another.
James_______________________________________________
Cocoa-dev mailing list (<email_removed>)
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/<email_removed>
This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Samvel | Mar 24, 02:55 | |
| Sherm Pendley | Mar 24, 04:24 | |
| Samvel | Mar 24, 04:36 | |
| Sherm Pendley | Mar 24, 04:42 | |
| Ken Thomases | Mar 24, 21:12 | |
| James Hober | Mar 25, 17:26 | |
| Steve Bird | Mar 25, 17:34 | |
| j o a r | Mar 25, 17:44 | |
| James Hober | Mar 25, 23:19 | |
| j o a r | Mar 25, 23:26 |






Cocoa mail archive

