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

The Archive Base Latest Questions

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

I’ve created a Person class, of which I instantiate two objects: int main(int argc,

  • 0

I’ve created a Person class, of which I instantiate two objects:

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        Person * __weak pweak = [Person new];
        Person *p = [Person personWithName:@"Strong" lastName:nil dateOfBirth:nil];
    }
    return 0;
}

The Person class overrides its dealloc method, so that it prints the name of the Person being deallocated.

Everything goes as expected, the weak variable doesn’t keep the Person instance alive, I see this in the log (“John” is the default name of a Person object):

2013-01-23 17:36:51.333 Basics[6555:303] John is being deallocated
2013-01-23 17:36:51.335 Basics[6555:303] Strong is being deallocated

However, if I use the factory method in the assignation to the weak variable:

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        Person * __weak pweak = [Person personWithName:@"Weak" lastName:nil dateOfBirth:nil];
        Person *p = [Person personWithName:@"Strong" lastName:nil dateOfBirth:nil];
    }
    return 0;
}

this is what I see logged:

2013-01-23 17:44:16.260 Basics[6719:303] Strong is being deallocated
2013-01-23 17:44:16.262 Basics[6719:303] Weak is being deallocated

Am I doing something wrong?

These methods of the Person class may be concerned:

- (id)initWithName:(NSString *)name lastName:(NSString *)lastName dateOfBirth:(NSDate *)birth {
    self = [super init];
    if (self) {
        _name = name;
        _lastName = lastName;
        _dateOfBirth = birth;
    }
    return self;
}

+ (id)personWithName:(NSString *)name lastName:(NSString *)lastName dateOfBirth:(NSDate *)birth {
    return [[self alloc] initWithName:name lastName:lastName dateOfBirth:birth];
}
  • 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-17T16:18:05+00:00Added an answer on June 17, 2026 at 4:18 pm

    When you allocate an object via the alloc/init method ARC gives to the creator of the object the responsability to release it later (so when you store an object as __strong it will stay alive until somebody owns it and when you store it as __weak it gets deallocated because nobody owns it).

    From Apple Documentation (http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/memorymgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH)

    You own any object you create You create an object using a method whose name begins with “alloc”, “new”, “copy”, or
    “mutableCopy” (for example, alloc, newObject, or mutableCopy).

    When dealing with factory methods ARC treats returning variables as autoreleasing so they are released when the pool will be drained. ARC, in facts, converts your factory method to this:

    + (id)personWithName:(NSString *)name lastName:(NSString *)lastName dateOfBirth:(NSDate *)birth 
    {
       return [[[self alloc] initWithName:name lastName:lastName dateOfBirth:birth] autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.