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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:06:32+00:00 2026-05-27T03:06:32+00:00

Does the automatic reference counting release an object if I set the pointer to

  • 0

Does the automatic reference counting release an object if I set the pointer to nil or assign the pointer to another object?

For example doing something like that:

//in .h file

@interface CustomView : UIView
{
   UIView *currentView;
}


// in .m file:

-(void)createView1
{
   currentView = [[UIView alloc] init];
   [self addSubview:currentView];
}

-(void)createView2
{
   [currentView removeFromSuperview];

   // does the former view get released by arc
   // or does this leak?
   currentView = [[UIView alloc] init];
   [self addSubview:currentView];
}

If this code leaks, how would I declare *currentView properly? Or how would I make ARC “release” the currentView? thanks!

  • 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-27T03:06:33+00:00Added an answer on May 27, 2026 at 3:06 am

    With ARC you don’t need to think about release/retain.

    Since your variable will have been implicitly defined as strong there’s no need to set it to NULL – it’ll be released before it’s assigned to.

    Personally though I prefer to declare properties:

    @property (strong, nonatomic) UIView *currentView;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How does the new automatic reference counting mechanism work? Can someone explain
I get ErrorMessage: Automatic Reference Counting Issue Receiver type 'NSThread' for instance message does
I really like the idea of automatic binding generation like SWIG does. But it
I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge
In my program I am setting up core foundation variables using automatic reference counting.
I have an objective-C program and I am using ARC (Automatic Reference Counting), it
I am trying to learn Automatic Reference Counting in iOS 5. Now the first
I have Automatic Reference Counting and Zombies enabled... I keep getting EXC BAD ACCESS
I am new to Automatic Reference Counting with LLVM and Objective-C, and have a
Whenever I tap newButton my app crashes. I am using automatic reference counting. Edit:

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.