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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:42:51+00:00 2026-05-22T12:42:51+00:00

@interface: UIImageView *myImageView; @property (nonatomic, retain) UIImageView *myImageView; @implementation: @synthesize myImageView; – (void)viewDidLoad {

  • 0

@interface:

UIImageView *myImageView;

@property (nonatomic, retain) UIImageView *myImageView;

@implementation:

@synthesize myImageView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
}

What is the reference count for myImageView? 2 (1 from alloc, 1 from dot notation retain) or 3 (1 from alloc, 1 from dot notation retain, 1 from @property retain)

Do these two statements have the same reference count?

self.myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

and

myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

Also, I assume you release them in @implemenation and in dealloc method, correct?


EDIT:

I didn’t get the answer that I wanted, maybe my question is vague. I understand what dot notation, @property, @synthesize, and how setter and getter works. What I don’t understand is what happen when using “self.” and without “self.” regarding retain count. I actually ran retainCount method on myImageView object and it confirms my original, the “self.” case has a retain count of two off the bat (with alloc and property retain so it’s probably a good idea to use autorelease there). Now this lead to another question, if I were not to use autorelease, how do I go about this? release once in viewDidLoad and once more in dealloc would still result in a memory leak, right?

self.myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
NSLog(@"retain count dot: %d", [myImageView retainCount]);

2011-05-17 10:01:14.915 Test[1249:207] retain count dot: 2

myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
NSLog(@"retain count: %d", [myImageView retainCount]);

2011-05-17 10:03:14.715 Test[1278:207] retain count: 1

  • 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-22T12:42:52+00:00Added an answer on May 22, 2026 at 12:42 pm

    First: you shouldn’t make any assumptions about the reference count. It will be misleading at best.

    If you use the property access (self.myImageView = ...) then it will get retained automatically, thus you are leaking the UIImageView in viewDidLoad. You should use something like

    self.myImageView = [[[UIMageView alloc] init.... ] autorelease];
    

    Your last example (without the “dot” access) will modify the ivar directly, so it will not leak this new instance. BUT it will leak the old imageView that you override if you don’t release it before.

    I strongly recommend using the property access all the time. And don’t forget to clean up in dealloc:

    [myImageView release], myImageView = nil;
    

    Some people prefer self.myImageView = nil; but this may have side effects.

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

Sidebar

Related Questions

I have a property defined in a class like so: @interface myClass UIImageView *drawImage[4];
Why counter variable equals 3, not 2? @interface ScoreView : UIImageView ... - (id)initWithFrame:(CGRect)frame
I created UIImageView with the help of Interface Bulder. Now I want to place
I created a UITableViewCell in Interface Builder which I have added a UIImageView and
I initialize a view(Image) through: Image *myImageView = [[Image alloc]init]; myImageView.myId = randomImageNumber; [myImageView
After adding a UIImageView to Interface Builder and assigning a png filename to it,
I have the following code: @interface NeighborProfileViewController : UIViewController { UIImageView * profPic; UITextView
#import <UIKit/UIKit.h> @interface ProfileViewController : UIViewController { UIImageView *profPic; UILabel *name; UILabel *hosted; UILabel
Interface Builder can be used for basic dependency injection in a Cocoa app, but
The Interface Segregation Principle (ISP) says that many client specific interfaces are better than

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.