As for the scope - that applies to basic types (Boolean, int, char, struct) which are allocated on the stack. These are freed when the method returns; no need to worry about them.
If you're dealing with pointers which you alloc (or malloc) memory for, they are allocated on the heap, and are not freed when the method returns. If garbage collection is off and you don't free them, they leak.
Obviously you are correct but I want to address this a little more because I believe the question is mostly related to my new method of doing this.
First thing to remember, all objects in Obj-C are allocated on the heap meaning if you make it and its retain count is greater than zero it will still be in the same place with the same data inside it for the life of your application.
Second thing to know is that the keyword static makes a variable into what is basically an instance variable for that single method*. Every time the method is called it has access to those static declared pieces of memory.
So the way the new method works is EXTREMELY similar to the way the old method worked. The only major change is that the very first call to the method CREATES the storage the method will use to store all the subviews.
It creates it and stores the pointer to that storage inside its own little static space.
Then essentially all that needs to happen is that all subsequent calls store all their subviews int that storage as before, and then they all return, the very first call returns the storage.
The key important ideas to keep in mind is how does each subsequent call to allSubviews know not to make the storage again, and not to return anything.**
1: Checking if storage is nil, makes it possible to make the storage if it isn't there, and use the storage if it is.
2: Each function call will get its own BOOL isFirstCall with the initial value set to NO. IF storage is nil, then it gets toggled to YES, but ONLY for the funcion call where storage is nil. For all the others it stays NO.
3: After adding all the subviews and recursively calling allSubviews on those subviews, the method checks that isFirstCall and simply returns nil right then if it is NO. This stops that particular function from continuing at that moment.
3: After doing the exact same thing, and all of them returned, the initially called allSubviews basically wants to return the storage and then set storage to nil to prime the next call of the allSubviews method. This is not possible in this order so it makes a stack copy of that pointer, sets the static pointer storage to nil, and returns the stack copy instead.
*works for C functions too
** they could return something as long as they don't set the storage pointer back to nil