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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:17:01+00:00 2026-06-15T16:17:01+00:00

Can someone explain the difference between the following (using ARC), where myObj is defined

  • 0

Can someone explain the difference between the following (using ARC), where myObj is defined as

@property(nonatomic, weak) MyType *myObj;

Assignment via local variable:

MyType *_myObj = [MyType new];
self.myObj = _myObj;

and

self.myObj = [MyType new];

In the former case, the object instance myObj appears to persist, while in the latter case, the instance is deallocated soon after the enclosing function is complete. What’s the difference? Shouldn’t they be the same?

[EDIT] I understand that I’ve specified weak, and my question still stands. Im not sure why this is getting downvoted.

  • 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-15T16:17:02+00:00Added an answer on June 15, 2026 at 4:17 pm

    Since your property is defined as weak, the assignment doesn’t increase the retain count.

    In the second bit of code, you create the object and assign it to the weak property. As soon as this is done, the created object is released and deallocated leaving the weak property reset to nil.

    In the first bit of code, you assign the created object to a strong local variable. You then assign the strong local variable to the weak property. As long as the local variable is in scope, the created object has a reference. As soon as the local variable goes out of scope, the object will be released and deallocated leaving the weak property set to nil.

    THe end result is the same. When the method competes, the property is left as nil because the created object has no other references to it. The only difference between the two is how quickly this happens.

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

Sidebar

Related Questions

Can someone please explain the difference between the following queries. The joins in the
Can someone please explain the difference between the following methods to me? it should
Can someone please explain the difference between the following cases and where would we
Can someone explain the difference between using define('SOMETHING', true); and $SOMETHING = true; And
Can someone please explain the difference between the following two options of Tortoise SVN
Can someone explain the difference between these two, the first one is taken from
Can someone explain the difference between apache mod_wsgi in daemon mode and django fastcgi
Can someone explain the difference between static NSString* CellIdentifier = @Cell; and NSString *CellIdentifier
Can someone please explain to me difference between extends and super in java generics
Can someone explain this to me? In particular the difference between: http://github.com/whymirror/greg and http://piumarta.com/software/peg/

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.