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 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 found that there is generally a singe type or namespace that takes
I have found that my HTML is, to be honest, very clunky. Small, simple
I have found some libraries or web services in PHP that does the job.
I have developed a simple location aware iPhone application which is functionally working very
I have a fairly complex application in Delphi 2006 that communicates through an ApdComport
I have found some in the Cappuccino website (vim, textmate and SubEthaEdit), but not
I have found jQuery to be a great tool to simplify my MVC Views.
I have found an interesting issue in windows which allows me to cause the
I have found a few libraries to edit MP3 tags (UltraID3Lib is great) but
I have found many tutorials about using Windows Server 2003 as a development machine,

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.