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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:47:58+00:00 2026-05-28T14:47:58+00:00

Without any preamble I want to show you problem I have in my program,

  • 0

Without any preamble I want to show you problem I have in my program, I commented out steps and my thoughts for that steps. (I didn’t include @interface part for shortness, it has same method with the same signature as in @implementation)

@implementation Dummy

- (int)testing:(NSError *__strong *)error 
{
    *error = [[NSError alloc] initWithDomain:@"hello" code:42 userInfo:nil]; 
    // 3. retain count = 1

    // 4. because of ARC 'error' object was released for this time 
    // (assembly output is my proof) object is deallocated
    // retain count = 0

    return 0;
}

@end

int main()
{
    NSError *e = nil; // 1. retain count = 0 (obviously)
    Dummy *dummy = [[Dummy alloc] init];

    [dummy testing:&e]; // 2. passing reference to an error object

    // 'e' for this time has to be just a trash, or nil maybe, 
    // but next log gives me correct output: 
    NSLog(@"%@ %li", [e domain], [e code]); // 'hello 42'

    return 0;
}

How does an error object exist after it death? I understand that using NSError *__autoreleasing * will be right way to go, and situation will be trivial in that case, but how compiler reasoning for this code, where is my mistake in judgements?

It’s a bit an artificial question, but I can’t throw out this situation from my head, I think I’m loosing something.

Here is part of disassembly for -[Dummy testing:]

callq  0x100000e8c <dyld_stub_objc_msgSend>
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rdx
mov    %rax,(%rcx)
mov    %rdx,%rdi
callq  0x100000e92 <dyld_stub_objc_release>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
retq   

If I understood correctly, there is only one object in this method, and it’s clearly released, not autoreleased or something else.

  • 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-28T14:47:59+00:00Added an answer on May 28, 2026 at 2:47 pm

    I suspect your confused about what’s getting released. I just checked the assembly output, and there is a call to objc_release(), though I’m not familiar enough with x86 assembly to actually trace precisely what’s going on. However, I do know that the code here is expected to emit something of the equivalent of:

    NSError *temp = [[NSError alloc] initWithDomain:@"hello" code:42 userInfo:nil];
    [*error release];
    *error = [temp retain];
    [temp release];
    

    and of course the optimizer will shrink that to

    NSError *temp = ...
    [*error release];
    *error = temp;
    

    So I think you’re seeing the call to objc_release() and thinking that your newly-allocated error is being released. It’s not. The previous value of *error is being released before the newly-allocated error is placed in that location.

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

Sidebar

Related Questions

I have an application that works without any problem in a spanish server. When
Problem is that application closes without any error, VS stays opened. I have multiple
I have made a program that divides without any arithmetic characters, here is the
I have two tables without any cascade deleting. I want to delete parent object
I have a ClickOnce application that deploys without any problems from a Win2K3 server
I have a simple (one view) application without any TextFileds. How can I show
I have a C# service that works without any problems on my laptop (Windows 7).
I have a pure text file without any HTML formatting. I want to search
I tried without any result. My code looks like this: #include stdafx.h #include <iostream>
We have a small embedded system without any video or serial ports (i.e. we

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.