Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Introduction to Objective-C From Structs to Objects

Why "Everything" in Objective C is pointers. I mean why I should declare NSArray instance variables in pointers.

How is it different from Java or C#. Yes I know its different but I need to understand why NS Objects are declared as pointers. From the Inside Infrastructure please.

Thank you

1 Answer

Stone Preston
Stone Preston
42,016 Points

objects are declared as pointers mainly because that makes it extremely easy for them to be passed around in your code.

If you create an object as a pointer, no matter how large the object is the pointer variable is just a memory address, which is a tiny amount of memory. This makes it easy on the computer. It saves memory and time. When you want to pass that object around in your code you dont reference the actual object (thats very large and cumbersome) you reference the pointer to that array, the teeny tiny memory adress.

If you created an array for instance that had 1000 items in it and was not a pointer and you passed it around to a method or something it would have to copy that whole array. That takes memory and time and that is not good

VERY good answer