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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:30:55+00:00 2026-06-13T02:30:55+00:00

I have found how to implement singleton in objective c (Non-ARC). Matt Galloway’s singleton

  • 0

I have found how to implement singleton in objective c (Non-ARC).

Matt Galloway’s singleton

// AppTools.h in my code

@interface AppTools : NSObject {

    NSString *className;
}

@property ( nonatomic, retain ) NSString *className;

+ ( id ) sharedInstance;

@end    // AppTools


// AppTools.m in my code

static AppTools *sharedAppToolsInstance = nil;

@implementation AppTools

@synthesize className;

- ( id ) init {

    self = [ super init ];
    if ( self ) {
        className = [ [ NSString alloc ] initWithString: @"AppTools" ];
    }
    return self;
}   // init

- ( void ) dealloc {

   // Should never be called, but just here for clarity really.
   [ className release ];
   [ super dealloc ];
}   // dealloc

+ ( id ) sharedInstance {

    @synchronized( self ) {
    if ( sharedAppToolsInstance == nil )
        sharedAppToolsInstance = [ [ super allocWithZone: NULL ] init ];
    }
    return sharedAppToolsInstance;
}   // sharedInstance

+ ( id ) allocWithZone: ( NSZone * )zone {

    return [ [ self sharedInstance ] retain ];
}   // allocWithZone:

- ( id ) copyWithZone: ( NSZone * )zone {

    return self;
}   // copyWithZone:

- ( id ) retain {

    return self;
}   // retain

- ( unsigned int ) retainCount {

    return UINT_MAX;    // denotes an object that cannot be released
}   // retainCount

- ( oneway void ) release {

    // never release
}   // release

- ( id ) autorelease {

    return self;
}   // autorelease

I’d like to know how to work allocWithZone: in sharedInstance method.
On this, the allocWithZone: method’s receiver is ‘super’ and ‘super’ is NSObject.
Though return value is NSObject instance, it is substituted to sharedInstance.

Where is className’s memory room then?
I don’t know how to work this part of the code.

Thank in advance.

  • 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-13T02:30:56+00:00Added an answer on June 13, 2026 at 2:30 am

    You ask “Where is className’s memory room then?”

    Most classes do not implement alloc or allocWithZone themselves but rely on the implementation inherited from NSObject. The NSObject implementation allocates an object of the original calling class.

    So in your example AppTools does override allocWithZone, this implementation invokes NSObject‘s allocWithZone via a call to super, and NSObject‘s method performs the actual allocation and returns an object of type AppTools.

    [Note: If you are wondering how NSObject‘s implementation knows what kind of object to allocate then this is simple – calling an inherited method does not alter the self argument to the method, alloc/allocWithZone are class methods, and the self argument of a class method references the class object (rather than an instance object of the class) itself.]

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

Sidebar

Related Questions

I have found a Tutorial here on how to implement drag and drop in
I have found that I often have to implement some sort of a scheduler
I have been using GRAILS since a year, It found very easy to implement
I am trying to make some code regarding USB HID devices. I have found
I have found a function which implement a switch statement --> File = open('/file.txt','r')
I have found DoctrineExtensions module that has implement some useful MySQL functions. But I
I want to implement a temporal database using mysql. I have found out that
I am trying to implement multibinding in Silverlight using VB.Net. I have found a
Have found a function address in a DLL. Have no source code for this
So far the only solution I have found is to subclass QItemDelegate and implement

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.