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

  • Home
  • SEARCH
  • 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 994105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:31:44+00:00 2026-05-16T06:31:44+00:00

I came across a problem that seems to be called drowning in autorelease pools.

  • 0

I came across a problem that seems to be called “drowning” in autorelease pools.

My code creates and destroys objects correctly. However, I use some class methods that autorelease several variables without my knowing about it. Considering they loop thousands and thousands of times every minute… I find myself drowning in thousands of unreleased objects lost somewhere in the program.

2 questions:

  1. So either I do not use class methods AT ALL – is that a permanent solution, or, even so, will some instance methods (Foundation, UIKit) still autorelease objects without my knowing about it?

  2. or I can alloc an autorelease pool prior to calling class methods and draining it after calling the class methods – would this be a permanent solution?

  • 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-16T06:31:45+00:00Added an answer on May 16, 2026 at 6:31 am
    1. Just because you don’t use a class method doesn’t mean you’re going to avoid autoreleased objects. For example: NSString * path = [anotherString stringByAppendingPathComponent:@"foo"] returns an autoreleased object, yet no class methods were involved. As far as I know, the only way to avoid autoreleased objects is to not use objects. If you really want to go that route, check out CoreFoundation. (I do not recommend going that route.)

    2. If you do have some crazy factory method that creates tons of autorelease pools, then I’d probably do something like this:

      + (id) crazyFactoryMethodWithFoo:(id)foo {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        id returnValue = nil;
        //generate gobs of autoreleased objects
        returnValue = [something retain];
        [pool release];
        return [returnValue autorelease];
      }

      By explicitly retaining the return value before draining the pool, you ensure that the return value will live beyond the destruction of the autorelease pool. You then balance that retain by autoreleasing the return value and returning it.

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

Sidebar

Related Questions

i came across this problem, my code in the viewWillAppear method is not executed
I just came across this weird problem that is happening in IE. In the
I recently came across some Java code that simply put some strings into a
I came across an old problem that you Mathematica/StackOverflow folks will probably like and
I was experimenting with some examples and came across a problem that if we
I recently came across a big problem, as I have a system that's paying
I am working on a small project and I came across that problem. The
I came across this excellent article that solves the problem of enumerating disconnected drives
I came across a strange problem today that i could understand the reason. Take
I looked around but nothing that I came across seems to be working for

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.