• 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: Protecting singleton objects from releasing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Protecting singleton objects from releasing


  • Subject: Re: Protecting singleton objects from releasing
  • From: Dietrich Epp <email@hidden>
  • Date: Sat, 15 Feb 2003 04:14:54 -0800

On Friday, Feb 14, 2003, at 04:11 US/Pacific, Angela Brett wrote:

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

Why do you want to do that? It seems to me that if anyone releases an object, singleton or otherwise, which they have not alloced, copied or retained, is at fault for doing so. The class shouldn't be protecting client code from its own errors. If the singleton is accessed through [NSProcessInfo processInfo] or similar then it ought not be released anyway unless it's retained first, and it's not NSProcessInfo's job to police that. Or is there a more advanced concept here which I'm missing?

The concept is putting in a token piece of code which prevents possible errors. Note the value of -retainCount, prescribed in the documentation for the NSObject protocol.

- (id)retain {
NSLog (@"Whoops! I was retained");
return self;
}

- (void)release {
NSLog ...
}

- (void)autorelease {
NSLog ...
}

- (unsigned)retainCount {
return UINT_MAX;
}
_______________________________________________
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: 
 >Re: Protecting singleton objects from releasing (From: Angela Brett <email@hidden>)

  • Prev by Date: Re: embedding libraries
  • Next by Date: CGrafPtr???
  • Previous by thread: Re: Protecting singleton objects from releasing
  • Next by thread: Re: Protecting singleton objects from releasing
  • Index(es):
    • Date
    • Thread