Why do we need items=nil;?


#1

Hello,

I am reading the objective-c chapter and in the #import “BNRItem.h” after the for loop we have the items = nil

If I remove it, the program still works. What is the significant of having it there?

How do I read this line? Does it say: Set the entire items array to nil?
Is it setting the pointer to nil?
or
is it setting what the pointer is pointing to, to nil?

thank you.


#2

It’s not necessary for the program to run correctly because the program exits right away. The code is a bit conceptual because we can’t build anything large enough to see the real issues with memory leaks yet (and creating a memory leak in an ARC application is pretty hard).

So, this line is setting the items pointer to nil, and because the items pointer is the only reference to the NSMutableArray, the NSMutableArray is destroyed.


#3

Thank you Joe