I have a basic question about subclassing a class with objects:
@interface Myclass : NSObject{
UIImage *image;
NSString *string;
ParticleSystem *system;
Object *obj;
Object2 *obj2;
}
If I subclass this MyClass class, and I initialise only a few of these objects defined in the superclasses header, what happens to all the other unallocated definitions in terms of memory?
The reason I ask, I have a class with many, many definitions and i’ve been subclassing it for simplicity sake, but my subclass only needs a fraction of these definitions.
Is it worth just subclassing NSObject and redefining the needed variables rather than subclassing MyObject?
Thanks,
Oliver.
If you just have pointers in the class definition (eg,
SomeClassName* somePointerName;) then each pointer takes up one pointer location in each of your objects (4 bytes on iPhone).Though it’s occasionally convenient to do what you’re doing, you’re missing out on many of the benefits of object-oriented programming — you’re basically just making use of Objective-C’s storage management while coding cruddy C.