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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:49:35+00:00 2026-05-18T00:49:35+00:00

Either my debugger is broken or there’s something fundamental that I am not understanding.

  • 0

Either my debugger is broken or there’s something fundamental that I am not understanding.

I have some very basic code in a very basic command line program that should crash. However, it is not crashing.

int main (int argc, const char * argv[])
{
    NSString *string = [[NSString alloc] initWithString:@"Hello"];

    [string release];

    NSLog(@"Length: %d", [string length]);

    return 0;
}

The log statement prints “Length: 5” as you would expect for a valid string. However, the string should be deallocated by that point and an exec_bad_access error should be thrown.

I have tried this code with the debugger attached and without the debugger attached – both give the same result. I have also enabled (and disabled) NSZombie, which seems to have no effect (I initially thought this was the problem, since NSZombie objects are never deallocated – but it still does not crash with NSZombie disabled).

I have breakpoints set in my local .gdbinit file to break on things such as -[NSException raise] and objc_exception_throw. I also have breakpoints set on many methods on NSZombie in order to catch them.

fb -[NSException raise]
fb -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:]
fb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]

#define NSZombies
# this will give you help messages.  Set to NO to turn them off.
set env MallocHelp=YES
# might also be set in launch arguments.
set env NSZombieEnabled=YES
set env NSDeallocateZombies=NO
set env MallocCheckHeapEach=100000
set env MallocCheckHeapStart=100000
set env MallocScribble=YES
set env MallocGuardEdges=YES
set env MallocCheckHeapAbort=1

set env CFZombie 5

fb -[_NSZombie init]
fb -[_NSZombie retainCount]
fb -[_NSZombie retain]
fb -[_NSZombie release]
fb -[_NSZombie autorelease]
fb -[_NSZombie methodSignatureForSelector:]
fb -[_NSZombie respondsToSelector:]
fb -[_NSZombie forwardInvocation:]
fb -[_NSZombie class]
fb -[_NSZombie dealloc]

fb szone_error
fb objc_exception_throw

With these breakpoints set and NSZombie enabled, I should get something like [NSString length]: message sent to deallocated instance 0x100010d39 printed to the console, but I do not see this. I see the NSLog printing the length as 5.

I see similar behaviour with other classes such as NSURL and NSNumber. But some classes crash as expected, such as NSError and NSObject.

Does this have something to do with class clusters? Do they not follow the same rules in regards to memory management?

If class clusters are not related to this problem, the only other common feature I could see was that the classes which don’t crash in this way are all toll-free bridged with a Core Foundation counterpart. Could this have something to do with it?

  • 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-18T00:49:36+00:00Added an answer on May 18, 2026 at 12:49 am

    retain/release is a contract between the API and the programmer that when you follow the rule, it doesn’t crash. The contract doesn’t guarantee that if you doesn’t follow the rule, it does crash!

    In this case,

    [[NSString alloc] initWithString:@"Hello"]
    

    just returns the same object as @"Hello" as an optimization. The constant NSString is never deallocated; as an optimization, retain and release are (I think) ignored. That’s why it doesn’t crash.

    You can check my guess by comparing the pointer value of @"Hello" and string.

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

Sidebar

Related Questions

I have some code like the following that I'm running in a debugger in
I have a modelform that will either create a new model or edit an
Have some Perl code which is using the DBI module - (the code is
I have some buttons which are fixed either side of my page, they work
Is either: <a href=#><h1>text here</h1></a> or <h1><a href=#>text here</a></h1> correct. Is there any benefit
I am looking for either a FireFox extension, or a similar program, that allows
I would like to either prevent or handle a StackOverflowException that I am getting
I have a .net web application that makes heavy use of oracle stored procedures.
Can I use DDD (Data Display Debugger) in Eclipse, either by configuring Eclipse or
I'm hitting a compile error in VS2010 with code that compiles cleanly in VS2008.

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.