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 9298287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:17:10+00:00 2026-06-18T22:17:10+00:00

So I have a singleton and Im trying to understand the difference between these

  • 0

So I have a singleton and Im trying to understand the difference between these two implementations: functionally I have tried running my code with both of them and they both work

However, I notice that in the 1st implementation there is no [self alloc] being called instead the call is to [super alloc]. Im a bit perplexed by this. It seems to work but it seems a bit magical so Im wondering if someone can clarify

1st way:

 +(id)getSingleton
 {

    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
    locMgrSingleton = [[super alloc] init];

        });

     return locMgrSingleton;

 }

Another way

 +(id)getSingleton
 {
     @synchronized(self)
     {
         if (locMgrSingleton == nil)
         {
             locMgrSingleton = [[self alloc]init];
             NSLog(@"Created a new locMgrSingleton");
         }
         else
        {
            NSLog(@"locMgrSingleton exists");
         }

     }

     return locMgrSingleton;
 }
  • 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-06-18T22:17:11+00:00Added an answer on June 18, 2026 at 10:17 pm

    Using [self alloc] vs [super alloc] makes no difference unless the class also overrides +alloc. That said, it should be calling [self alloc]. I’ll bet it’s calling super because this was probably adapted from an implementation that override +alloc to return a singleton.

    In any case, the difference between the two patterns, besides self vs super, is explained in my answer to this other question, but in short, dispatch_once() is the modern way to do this. It’s faster than @synchronized, and carries more semantic meaning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing set of singleton WCF services. They are long-running processes that
I have 4 singleton classes with private constructors and I'm trying to create bean
Possible Duplicate: What should my Objective-C singleton look like? I am trying to understand
I have spent hours trying to understand why my logger class does not work.
I have a singleton here that I am trying to use the same instance
I'm trying out some code from a singleton base class article . But when
I have a Singleton to manage some variables I need in various places in
I have a singleton class for global access to config information. This singleton class
I have a Singleton that is accessed in my class via a static property
I have a singleton object that use another object (not singleton), to require some

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.