Re: Protecting singleton objects from releasing
Re: Protecting singleton objects from releasing
- Subject: Re: Protecting singleton objects from releasing
- From: publiclook <email@hidden>
- Date: Sat, 15 Feb 2003 17:38:03 -0500
A question was asked:
>
Is there any "recommended" way to protect singleton objects (e.g.
>
[NSProcessInfo processInfo]) from releasing? Overriding the release
>
method comes in mind, but I am wondering if there are better ways...
I recommend not protecting against this at all.
Protecting against this is like protecting against de-referencing NULL
pointers. If a programmer releases a singleton that she did not
previously retain, she gets what she deserves: a big bug.
People who use Cocoa and objects derived from Cocoa classes MUST follow
Cocoa's memory management rules in all cases period. If there are
exceptions to the rules then they better be documented with strobe
lights or something. Cocoa's system is only practical if it is
ubiquitously applied.
Writing a single extra line of code to protect programmers from
"accidentally" releasing any object that they didn't previously
allocate, copy, or retain is a total waste of time because any
programmer who doesn't follow the rules is screwed no matter what and
you can't save them.
I doubt whether any of Cocoa's singleton objects protect programmers
from inappropriately releasing them.
If you can't live with Cocoa's memory management then don't use Cocoa.
If you use Cocoa then follow the rules and you don't need protection
from releasing singletons.
_______________________________________________
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.