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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:30:41+00:00 2026-05-17T02:30:41+00:00

I have three layers, the bottom layer is written in C++ and the other

  • 0

I have three layers, the bottom layer is written in C++ and the other two middle and top layers are both in Objective-C.

The C++ layer stores a reference to a class in the middle layer, and the middle layer also stores a reference to a class in the top layer.

Upon receiving a request from the middle layer, the bottom layer is responsible for asynchronously call a method in the middle layer which in turns call a method in the top layer.

Unfortunately, my code reports errors like:

* _NSAutoreleaseNoPool(): Object 0x523e50 of class NSCFNumber autoreleased with no pool in place – just leaking
Stack: (0x95c83f0f 0x95b90442 0x28d3 0x2d42 0x95b96e0d 0x95b969b4 0x93a00155 0x93a00012)

The problem is that the method in the top layer was called from a C++ POSIX thread which has no autorelease pool. The only solution I could come up is add the following in the middle layer:

bool temp = false;

- (void) method ...
{
  if (!temp)
  {
    temp = true;
    NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];    
  }

  call_to_the_top_layer();
}

This works. My question is that would there be any other better solution? This is ugly…

  • 1 1 Answer
  • 2 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-17T02:30:41+00:00Added an answer on May 17, 2026 at 2:30 am

    As far as I understood your question, you have the bottom layer in a thread which calls the middle layer. As you already discovered you have to have an autorelease pool if you want to use the Cocoa framework (it’s not about Objective-C ;)).

    You should either create one at thread creation or create and release one for every request to middle layer. Your “solution” does create one on demand which lives until the end of the thread’s days

    Which one is best depends on your architecture:

    • How long is the thread living?
    • Is it okay to have only a single autorelease pool for it’s whole life?

    Update:

    When you release the temporary pool, you should be aware of exceptions if they may occur:

    id pool = [[NSAutoreleasePool alloc] init];
    @try {
        …
    } @finally {
        [pool release];
    }
    

    If you do not have/use Objective-C exceptions DarkDust’s answer is the correct way.

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

Sidebar

Related Questions

I have a three tier system, SQL Server backend, hand written data access layer,
I have an asp.net mvc application with three layers: - data layer with entities
I have an MSMQ-based system with three layers that communicate with each other. For
I have two divs, both with position:absolute; , one inside the other. The parent
I have three layers, two of which are hidden using CSS. I would like
In a visual studio project I have three layers, Data Layer, Business Layer and
I have an application with three layers (Presentation, Business Logic, and Data Access). In
I have three files: one called sql.php witch has a class db that I
I have three tabs. When I press the tab button on the bottom, is
I have a screen with a background image and two buttons at the bottom.

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.