#memory management

10 posts with this tag

Calling a class method from an instance method

January 28, 2011

A colleague recently came to me with a bug in his code, that he just couldn’t solve. He was attempting to call a static/class method from inside an instance method of his class using self, assuming that as self was an instance of the class it would have access to all the methods defined in that class. Example code: + (int)returnSomething{ return 1; } - (void)doSomething{ int someValue = [self returnSomething]; } The error occurred at line int someValue = [self returnSomething];, at first I could…

What `isa` is for

January 28, 2011

When using the debugger within Xcode, you see that each object has a isa variable. For those, like me, curious about what is does. When you use alloc on a class, you are actually creating space in memory which is temporary filled, at the bottom of this space you point to another memory address. This memory address is the class object's meta self i.e. its object blue print. It is this memory address that "isa" holds. When it comes to creating (init'ing) the object, it uses this isa value to get th…

Function vs Method

December 14, 2010

A function is a section of code that is called by name. It can be passed data to operate on and can optionally return data. All data that is passed to a function is explicitly passed. A method is a section of code that is called by name that is associated with an object. The key differences between a function and a method are: A method is implicitly passed the object for which it was called A method is able to operate on data that is contained within the class (remembering that an object is an instance o…