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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:39:11+00:00 2026-06-08T08:39:11+00:00

I just started with iOS programming recently, and assumed that I understood Objective-C reference

  • 0

I just started with iOS programming recently, and assumed that I understood Objective-C reference counting, but seems I didn’t… The following code runs completely but makes my app crash afterwards with EXC_BAD_ACCESS (code 1 or code 2).

I am not using ARC (PhoneGap-based project).

for(int i = 0; i < 10; ++i)
{
    UIImage *a = [UIImage imageNamed:@"NavigationBarBackButtonBlack.png"];
    UIImage *b = [a resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 7)];
    NSLog(@"a has %d retains, b has %d retains, a==b == %d\n", [a retainCount], [b retainCount], a==b ? 1 : 0);
    [a release];
    [b release];
    NSLog(@"#%d\n", i);
}
NSLog(@"FINISHED\n");

Output is as I’d expect:

a has 1 retains, b has 1 retains, a==b == 0
#0
a has 1 retains, b has 1 retains, a==b == 0
#1
a has 1 retains, b has 1 retains, a==b == 0
[...snip...]
a has 1 retains, b has 1 retains, a==b == 0
#9
FINISHED

What’s the problem here? Is there some autorelease going on, or does the capped image keep a reference to the original? No idea.

  • 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-08T08:39:13+00:00Added an answer on June 8, 2026 at 8:39 am

    imageNamed and resizableImageWithCapInsets both return autoreleased objects. You should not release them manually.

    In other words: if you did not alloc, copy or retain it, you should not release it!

    And as a last hint: forget about the retainCount property, it is useless for you.

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

Sidebar

Related Questions

I have recently started programming for the iOS Platform but now I need some
I've just started iOS drawing programming and I found out that the coordinate system
Just getting started with Obj-C and iOS programming. I have some code that loads
I have just started programming on iOS a couple of weeks ago, so sorry
I just started iOS development am currently developing an application that just reads data
I just started to learn iOS programming and I have a problem with inheritance.
I just started to learn iOS programming and I have a problem with inheritance.
I just started learning iOS development. I've seen example code that creates a ViewController
I have just started to learn how to code iOS apps. I have made
A bit of a newbie question for iOS, just started learning about Core Graphics

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.