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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:17:38+00:00 2026-05-21T11:17:38+00:00

I encountered a weird behavior of Cocoa Touch / iOS involving static method. If

  • 0

I encountered a weird behavior of Cocoa Touch / iOS involving static method. If you implement a static method ‘load’ in any class, Cocoa Touch / iOS will automatically call that method when the application starts executing. Even if you do not refer to that class from the main execution thread, it’ll still be called first, no matter what.

I’ve managed to replicate the behavior when compiled on SDK 4.2 on Xcode 3.2.5 and SDK 4.3 on Xcode 4.0.1, and when running from both iPhone simulator and iPhone device.

Here’s how to replicate:

Create a new class and name it however you want. In the interface declare a static method ‘load’ (any return type):

+ (void)load;

Then implement it:

+ (void)load {
    NSLog(@"What the?");
}

Compile (make sure the new class is compiled along) and run the app (on simulator or device). While the app is starting, switch to and monitor GDB view. You’ll see “What the?” echoed there even though by logic no other code refers to the class or the method.

And on top of that, if you use any autorelease code in the method, you’ll get an error that shows that the method is called before even the int main() method (the super gateway of all C applications existing out there).

The following code:

+ (void)load {
    NSLog(@"Hello %@", [NSString stringWithString:@"World"]);
}

Will give you something that looks like:

2011-04-21 00:41:53.828 AppName[548:707] *** __NSAutoreleaseNoPool(): Object 0x8fe8c of class NSCFString autoreleased with no pool in place - just leaking
2011-04-21 00:41:53.838 AppName[548:707] Hello World

So the questions are, does anyone know why Cocoa Touch / iOS calls this method? What’s so special about method name ‘load’? And last but not least, is this a feature or a bug?

p/s: I discovered this behavior when it just so happened that the static method ‘load’ that I implemented instantiates many autoreleased objects and I was perplexed by the multiple __NSAutoreleaseNoPool() warning messages in GDB.

  • 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-21T11:17:38+00:00Added an answer on May 21, 2026 at 11:17 am

    NSObject has a +(void)load method. Here is what the documentation says :

    Invoked whenever a class or category
    is added to the Objective-C runtime;
    implement this method to perform
    class-specific behavior upon loading.

    So this is working as intended, and is not a bug. This method gets called by every class when it is added to the runtime, which is before any code begins to be executed.

    Source: NSObject documentation

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

Sidebar

Related Questions

I encountered following weird behavior yesterday. It seems a compiler bug to me or
Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load : I have
I have encountered some strange Perl behavior: using a Posix character class in a
I was working on HTTP post using java and encountered a weird stream behavior.
As part of developing some ajax history behavior I encountered a weird thing: (my)
I've just encountered a weird problem, I'm trying to printf an integer variable, but
I encountered a, at least to my expectations, strange behavior in the binary serialization
I've encountered a weird situation: Messages are sent from ServerA to ServerB. It goes
I have encountered a weird situation while updating/upgrading some legacy code. I have a
I encountered a weird behaviour in Perl. The following subtraction should yield zero as

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.