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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:52:49+00:00 2026-06-12T16:52:49+00:00

I’m going through the Big Nerd Ranch for IOS (3rd edition). And I’m on

  • 0

I’m going through the Big Nerd Ranch for IOS (3rd edition). And I’m on the ARC Memory Management chapter. It’s trying to explain retain cycles and it has us modify a short console application like so:

Header for BNRItem:

@interface BNRItem : NSObject
{
    NSString *itemName;
    NSString *serialNumber;
    int valueInDollars;
    NSDate *dateCreated;

    BNRItem *containedItem;
    BNRItem *container;
}
+ (id)randomItem;

- (void)setItemName:(NSString *)str;
- (NSString *)itemName;

- (void)setSerialNumber:(NSString *)str;
- (NSString *)serialNumber;

- (void)setValueInDollars:(int) i;
- (int)valueInDollars;

- (void)setContainedItem:(BNRItem *)i;
- (BNRItem *)containedItem;

-(void)setContainer:(BNRItem *)i;
- (BNRItem *)container;

- (NSDate *)dateCreated;

- (id)initWithItemName:(NSString*)name valueInDollars:(int)value serialNumber:(NSString *)sNumber;
- (id)initWithItemName:(NSString *)name andSerialNumber:(NSString *)sNumber;
@end

main file:

int main(int argc, const char * argv[])
  {

  @autoreleasepool {
    NSMutableArray *items = [[NSMutableArray alloc]init];
    BNRItem *backpack = [[BNRItem alloc] init];
    [backpack setItemName:@"Backpack"];
    [items addObject:backpack];
    BNRItem *calculator = [[BNRItem alloc]init];
    [calculator setItemName:@"Calculator"];
    [items addObject:calculator];

    [backpack setContainer:calculator];
    NSLog(@"Setting items to nil");
    items = nil;

  }
  return 0;
}

Now after this it says: “Per our understanding of memory management so far, both BNRItems should be destroyed along with their instance variables when items is set to nil”. It had prior to this have us override (void) dealloc to print out when our BNRItem gets destroyed.

So I run it and I’m suppose to see because backpack now has a strong reference to calculator neither get destroyed. Now in the console I see both getting destroyed but I think it’s because they get destroyed when the application ends. When I do a break point after setting items to nil nothing is getting destroyed. Which is what the book says should happen… but then it makes me set container to

__weak BNRItem *container 

and then when I run it still nothing gets destroyed. I’m assuming because there are still pointers to it that I did not set to nil? Even though the book does not mention to do so at this point. So I understand the books explanation (I think), but in practice it’s not happening.

  • 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-12T16:52:50+00:00Added an answer on June 12, 2026 at 4:52 pm

    I trusted the auto completion.

    [backpack setContainer:calculator]
    

    should have been

    [backpack setContainedItem:calculator]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
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.