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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:58:24+00:00 2026-06-09T23:58:24+00:00

I have two questions, but let’s start with the more clearly confusing due to

  • 0

I have two questions, but let’s start with the more clearly confusing due to simplicity question first.

-(void)OnNewFrameData:(NSData *)FrameData 
{
    UIImage * I = [UIImage imageWithData:FrameData];
    [I release];
}

If I do not release I, I experience a memory leak. Yet, I never retained I. Can somone explain this? (FrameData is managed by the caller entirely.)

Then I have another question about retained properties. Take the same code above, assign I to a retained property J, then assign nil to the same retained property, there should not be any leak, but I am leaking memory again. And I can release the retained property as well, but I still get a leak.

@property (retain) UIImage * J;

...

-(void)OnNewFrameData:(NSData *)FrameData 
{
    UIImage * I = [UIImage imageWithData:FrameData];
    self.J = I;
    // I can also add here [self.J release]; and it still leaks...
    self.J = nil;
    [I release];
}

Insight into these two confusing apparent contradictions from what I have learned from both the documentation and from threads here at stackoverflow would be MUCH appreciated.

  • 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-06-09T23:58:26+00:00Added an answer on June 9, 2026 at 11:58 pm

    So I tried an experiment with the following code…

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        UIImage * Img = [[UIImage imageWithData:FrameData] retain];
        [pool drain];
    
        int n = [Img retainCount];
    

    In the code above, Img’s retain count comes back 1. If I remove the auto release pool, it is 2. This is absolutely clear evidence that imageWithData: returns an autoreleased object, and that is exactly what we all expect.

    So my only conclusion is that the pool wasn’t releasing Img soon enough and they were pooling with each successive image coming over the wire. Eventually I ran out of memory.

    If no one has any other ideas on the first part of the original problem I would have to go with this as the answer.

    I still have no clue regarding the second issue.

    UPDATE:

    What had confused me all this time is how do objects on the main thread flagged for auto release get released in a timely manner? I always thought that the auto release was like a garbage collector that operated whenever the memory pool was running out of memory. But looking back at the literature, it is clear that GB is NOT what the auto release pool is about, since it is available in a non GB environment. The auto release pool doesn’t release any objects until the pool is destroyed by the drain message.

    So what about main thread objects? Why do they not accumulate until the program ends? Because (I speculate here, but it is the most logical explanation) every time the framework calls into one of our class objects (UPDATE: I am talking about the framework calling our code whenever it dispatches an event), it first sets up a new auto release pool. Thus all objects in any method call to one of our class objects made by the framework is surrounded by a fresh pool and all objects flagged for auto release are released when the framework receives control back from our code.

    If anyone has any information to shed more light onto this I would very much like to hear from you.

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

Sidebar

Related Questions

I have two problems but I'll post them as 2 different questions. Let's start
I have previously asked two questions Question 1 and Question 2 but there is
I am not sure if people find this obvious but I have two questions:
guys I have two question to ask, they're easy, but bothering me for a
I'm re-asking this question but with a different framework this time. I have two
I have a simple but subtle question. Below you see two different declaration variants
I have actually two questions but they are kind of related so here they
My question is kinda simple... Let's suppose I have two simples tables on a
I ultimately have two areas with a few questions each about Entity Framework, but
I have two related questions. First, i have a some information such as: (732,

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.