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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:21:50+00:00 2026-06-10T12:21:50+00:00

I am new to Objective-C. Here is my understanding (as in comments) concerning ARC

  • 0

I am new to Objective-C. Here is my understanding (as in comments) concerning ARC of some simple code for programmatically adding a subview. Please correct me if I am wrong. Especially on this statement:

“ViewController points to myView weakly” ACTUALLY means that _myView
(ViewController’s ivar) points to a UIView object weakly

// _myView stores a pointer pointing to a UIView object
// "ViewController points to myView weakly" ACTUALLY means that _myView (ViewController's ivar) points to a UIView object weakly

@interface ViewController ()
@property (nonatomic,weak) UIView *myView;
@end

@implementation
@synthesize myView = _myView;
@end

- (void)viewDidLoad
{
    [superviewDidLoad];
    CGRect viewRect = CGRectMake(10, 10, 100, 100);

    // a UIView object is alloc/inited    
    // mv is a pointer pointing to the UIView object strongly (hence the owner of it)
    UIView *mv = [[UIView alloc] initWithFrame:viewRect];

   // _myView points to the UIView object weakly 
   // Now the UIView object now have two pointers pointing to it
   // mv points to it strongly
   // _myView points to it weakly, hence NOT a owner 
   self.myView = mv;

   // self.view points to the UIView object strongly
   // Now UIView object now have THREE pointer pointing to it
   // Two strong and one weak
   [self.view addSubview:self.myView];
}   

// After viewDidLoad is finished, mv is decallocated. 
// Now UIView object now have two pointer pointing to it. self.view points to it strongly hence the owner, while _myView points to it weakly. 
  • 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-10T12:21:52+00:00Added an answer on June 10, 2026 at 12:21 pm

    You are mostly correct, with the exception of this sentence:

    After viewDidLoad is finished, mv is decallocated.

    That’s where you are wrong. Remember, deallocation of an object only ever happens when everyone who retain‘s the object release‘s it. Thus, while you have release‘d the temporary variable mv, You still have one other source retaining it: self.view.subviews. Once mv is removed from the subview array, it can properly be cleaned up, _myView is set to nil, and you have no more leaks.

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

Sidebar

Related Questions

I'm new to Objective-C here, and still learning its syntax, so I'm experimenting some
I'm new to Objective-C, but please help me out here. What I'm seeing is
I'm new in objective-c, and I'm now trying to write a simple user-sign-in program
I'm new in objective-C and i wonder if its correct: I have a class
i'm new here, i'm new in iphone development, i'm new in Objective-c and i'm
I'm new to Objective-C and I'm trying to create a simple dictionary style app
Can anyone help me with this one? My objective here is to grab some
New to Objective-C and iOS development, would love a hand here! I have written
Still new to Objective C, and I'm having some trouble that I just can't
I'm new to Objective C and having trouble understanding why I am getting this

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.