advertisement

Article:
  Memory Management in Objective-C
Subject:   (Q) interchangeable pointers and objects
Date:   2003-12-09 17:35:27
From:   anonymous2
Response to: (Q) interchangeable pointers and objects

If you want to gain a better understanding of the relationship between a class and its instances, and find out what is happening "behind the scenes," I suggest you read the article below.


http://www.macdevcenter.com/lpt/a/2432


It takes careful reading, but is very valuable. Keep in mind that all objective-c objects are manipulated as pointers to an object that exists somewhere else in memory--the id type is implemented as a pointer to a class or instance. Classes are also objects. This is why a message can be sent to a class, as in the NSString initialization example. In [NSString stringWithCString:"hello"], NSString is actually a pointer to the object representing the NSString class, not to the NSString type. (I conjecture that the NSString type is actually not a type but a struct--structs behave somewhat like a typedef under certain circumstances). Maybe I've clarified things, or maybe I've just written an incomprehensible bunch of jargon. I can't tell. If this helps, good. If not, ignore it.