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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:31:26+00:00 2026-06-01T01:31:26+00:00

I got an EXC_BAD_ACCESS in main() , here is my code: int main(int argc,

  • 0

I got an EXC_BAD_ACCESS in main(), here is my code:

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
    [pool release];
    return retVal;
}

@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
@end

@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];
    [window addSubview:nav.view];
    [window makeKeyAndVisible];
}
@end

- (void) action: (id) sender
{
    [self highRetainCount];
}

@implementation TestBedViewController
- (void) highRetainCount
{
    UIView *view = [[[UIView alloc] init] autorelease];
    printf("Count: %d\n", [view retainCount]);

    NSArray *array1 = [NSArray arrayWithObject:view];
    printf("Count: %d\n", [view retainCount]);
    [array1 autorelease]; // If comment this line, everything will be OK
}
@end

The program stopped at main():

int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");

As the comment says, after commenting out [array1 autorelease];, everything was OK.

So here is my question:

  1. EXC_BAD_ACCESS often indicates using an object already released. Clearly there’s something to do with [array1 autorelease];, but I can’t understand their relationship.

  2. Why stopped at this position — main() — instead of somewhere else?

Newbie question 🙂

  • 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-01T01:31:27+00:00Added an answer on June 1, 2026 at 1:31 am

    arrayWithObject: returns an object you do not own. Therefore it is wrong for you to subsequently send it autorelease.

    See the Basic Memory Management Rules, specifically:

    • You must not relinquish ownership of an object you do not own

    and

    • You own any object you create

    You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).

    Also, as a more general point, don’t use retainCount. Unless you happen to be doing low-level hacking of the runtime or something, you don’t need it, and it won’t return anything of use to you.

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

Sidebar

Related Questions

Suddenly I got EXC_BAD_ACCESS on this line: int retVal = UIApplicationMain(argc, argv, nil, nil);
I've got a question. Where is the reason for EXC_BAD_ACCESS in the following code
Today I got a EXC_BAD_ACCESS ,so I debug the code to solve the problem.
Got myself in a bit of a pickle here ... working on a CMS
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I am new to cocos2d and suddenly got this EXC_BAD_ACCESS, I made a new
Here is the problem: The app crashes at the 2nd line, and I got
Ok I've got a dreaded EXC_BAD_ACCESS that I can't seem to track down but
I've got a strange problem here. I have a class that I'll call MainView
I subclassing TTTableMessageItemCell, got EXC_BAD_ACCESS runtime error. Anythign wrong? CustomTTTableSubtitleItemCell.h #import Three20/Three20.h @interface CustomTTTableSubtitleItemCell

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.