Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 787643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:14:10+00:00 2026-05-14T21:14:10+00:00

I have an object factory that hands out instances of a few constant, immutable

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:14:11+00:00Added an answer on May 14, 2026 at 9:14 pm

    You may also want to override copyWithZone: and autorelease:

    - (id)copyWithZone:(NSZone *)zone
    {
        return self;
    }
    
    - (id)autorelease
    {
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the convenient object factory template that creates objects by their type id
I have a factory that makes objects that depend on an external object, do
In C++ for Windows, I have some object factory that is supposed to create
I have a factory that is supposed to create objects that inherit from class
I have a Factory class that creates a Widget object. The Factory object needs
Problem I currently have a factory that depends on a few parameters to properly
I have a custom type MyClass and a factory class Factory that creates objects
If I have a factory that creates an object that needs an instance of
I have a factory class that populates objects with data. I want to implementing
I have a factory that builds the objects with longest lifetime in my application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.