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

  • Home
  • SEARCH
  • 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 884389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:44:33+00:00 2026-05-15T12:44:33+00:00

I have found a crash in an iPhone application with target iOS 4 that

  • 0

I have found a crash in an iPhone application with target iOS 4 that changes depending on the type of build.

The debugger is giving me nothing much to go on, it stops at

 UIViewController *result = [self factory](self);

with EXC_BAD_ACCESS. self is a class inheriting from NSObject (shown below as NSObjectInheritor). Zombies are enabled. I’ve tried changing method factory three ways with the following results.

This crashes in both debug and ad hoc builds…

- (FactoryMethod) factory;
{
    return [^ UIViewController * (NSObjectInheritor *newThing)
    {
      return [[ViewControllerClass alloc] initWithStuff:(boolValue ? foo : bar)];
    } autorelease];
}

This works in debug builds but crashes in ad hoc…

- (FactoryMethod) factory;
{
  return [^ UIViewController * (NSObjectInheritor *newThing)
  {
    if(boolValue)
    {
      return [[ViewControllerClass alloc] initWithStuff:foo];
    }
    else
    {
      return [[ViewControllerClass alloc] initWithStuff:bar];
    }
  } autorelease];
}

This works in both debug and ad hoc but is very ugly and redundant:

- (FactoryMethod) factory;
{
  if(boolValue)
  {
    return [^ UIViewController * (NSObjectInheritor *newThing)
    {
      return [[ViewControllerClass alloc] initWithStuff:foo];
    } autorelease];
  }
  else
  {
    return [^ UIViewController * (NSObjectInheritor *newThing)
    {
      return [[[ViewControllerClass alloc] initWithStuff:bar];
    } autorelease];
  }
}

My theory is that boolValue becomes inaccessible at the time the returned block is executed. It is

@interface SubclassOfNSObjectInheritor : NSObjectInheritor
{
  BOOL boolValue;
}

@property (readonly) BOOL boolValue;

(YES or NO assigned in SubclassOfNSObjectInheritor’s init of course) and

@synthesize boolValue;

in SubclassOfNSObjectInheritor’s implementation.

The final questions are – is my theory about what is wrong correct? Is the third way of doing it – noted as working in ad hoc and debug builds – safe? What is the best way to do this?

  • 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-15T12:44:33+00:00Added an answer on May 15, 2026 at 12:44 pm

    Your problem is twofold, first you are overreleasing your block and second, blocks are created on the stack, which is going away when your method returns (you’re basically returning a pointer into the previously destroyed stack frame).

    Instead, copy the block and auto release it before returning. You can do this in the objective-c way with a copy message, your you can call the Block_copy() function.

    Your crashing in various configurations is pure happenstance. So, to fix one of your implementations:

    - (FactoryMethod) factory;
    {
      return [[^(NSObjectInheritor *newThing)
      {
        if(boolValue)
        {
          return [[ViewControllerClass alloc] initWithStuff:foo];
        }
        else
        {
          return [[ViewControllerClass alloc] initWithStuff:bar];
        }
      } copy] autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an objdump of the crashing method. I found that the crash is
I currently have some code that will produce a crash dump when my application
I have found that I have no problem using require to load something like
I have found that call stack helps in finding the line number of a
I have found that it is impossible to write ( file_put_contents or simple fwrite
I have a little issue about my application iOS. When i'm using the iOS
I have found a situation where a WCF client can crash a WCF ServiceHost
I have a web application that uses a couple of PDF forms to create
For an iPhone app that has to have a bunch of data inserted before
I'm new to mono/iPhone and I'm developing an application that views a PDF document

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.