I have an object factory that hands out instances of a few "constant," immutable objects. I'd like these objects to be protected against bad memory management by clients. This is how I've overridden the class's key methods. Am I missing anything (code or other considerations)?
- (id)retain
{
return self;
}
- (NSUInteger)retainCount
{
return UINT_MAX;
}
- (void)release
{
// nothing.
}
Update for later Drive-by question readers: This was (by intention) a special-case, double-black-diamond Cocoa question. If you're trying to create a regular singleton, see the answers below regarding shared instances, etc. This question (and the chosen answer) falls into the "you should be sure you know what you're doing" before choosing this implementation strategy.