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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:15:56+00:00 2026-05-20T09:15:56+00:00

I am debugging a weird memory management error and I can’t figure it out.

  • 0

I am debugging a weird memory management error and I can’t figure it out. I noticed that some of my objects are staying in memory longer than expected. I checked all my memory management and finally got to the very improbable conclusion that some of my autorelease operations don’t result in a release. Under what circumstances is that possible? I created a small testing Canary class that logs a message in dealloc and have the following testing code in place:

NSLog(@"On the main thread: %i.", [NSThread isMainThread]);
[[[Canary alloc] init] autorelease];

According to the code we’re really on the main thread, but the dealloc in Canary does not get called until much later. The delay is not deterministic and can easily take seconds or more. How is that possible? The application runs on a Mac, the garbage collection is turned off (Objective-C Garbage Collection is set to Unsupported on the target.) I am mostly used to iOS, is memory management on OS X different in some important way?

  • 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-20T09:15:57+00:00Added an answer on May 20, 2026 at 9:15 am

    There’s a blog post by Mike Ash called More Fun With Autorelease that explains the source of this problem. Quote:

    As everybody knows, every time you go
    through the event loop, Cocoa blows
    away the old pool and makes a new one
    for you, so that all of your
    autoreleased objects go away and your
    new ones go into a fresh pool. That
    way you never build up more objects
    than get produced during a single
    event loop cycle. The key word is “event loop”. In
    Apple’s infinite wisdom, things that
    aren’t real actual NSEvents don’t
    trigger the pool.

    I’m currently working on an app that
    spends a lot of time in the background
    doing dark, unspeakable things with
    NSStreams on the main thread. I
    encountered a bug where one of my
    objects can get destroyed in the
    middle of handling a stream event,
    which left it open to getting other
    stream events after it was
    deallocated. (…)

    The obvious fix was to simply do
    [[self retain] autorelease] before
    making the problem call. And fix it it
    did, except instead of my dealloc
    happening in the middle of my event
    handler, it never happened at all.

    Until I clicked on my app’s dock icon.

    At least the solution was easy. Post
    an NSApplicationDefined event in the
    stream event handler, and autoreleased
    objects get destroyed on schedule.

    I swear I have to read the blog from cover to cover, it’s a good time investment.

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

Sidebar

Related Questions

I've got a weird macro that I'm debugging and I can't seem to figure
I'm having some problems debugging my code as I can't work out where an
Does anyone know of a debugging utility that can debug some cakephp code line
I just noticed some weird behaviour with my Android 2.3.3 application. I can write
Today i was debugging some lines of code and i noticed a very weird
when debugging java code, in the stack trace, I noticed that something in the
I'm seeing some weird behaviour debugging my C# code - I cant post my
I've been debugging some app lately with valgrind, and I'm getting very weird reports
I have a weird error in my code. I'm trying to read some characters
So I am debugging some code and keep getting a weird result. I am

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.