Assume I have an array employees1:
[
{"id":"1", "name":"Bill"},
{"id":"2", "name":"Jhon"},
{"id":"3", "name":"Almas"},
]
OR an Array employees2 with Employee objects:
@interface Employee : NSObject {
NSNumber *employeeID;
NSString *name;
}
@property (nonatomic, retain) NSNumber *employeeID;
@property (nonatomic, retain) NSString *name;
The second case is more Object Oriented which is easy to use in large projects.
If I have a lot of employees, will employee2 array allocate more (2x, 3x …) memory than employee1? How much they differ?
In most cases, likely lower memory footprint with the object-oriented model because you aren’t requiring the overhead of
NSDictionaryinstances.However, you can (as I just did) write a trivial test case and run it on Instruments to prove it to yourself. In this case, I constructed such a test with your model, creating 10K objects and showed that your overall memory footprint was ~23% lower using custom objects.
Always better to test, although honestly the object-oriented model is so much clearer that in the long run, a small difference in memory footprint even if it were a negative difference may be better.
To editorialize: I see numerous questions here and elsewhere that pertain to the construction of the entire model layer of the application on
NSDictionaryandNSArray. I can’t imagine what a headache it would be to maintain that code in perpetuity. So much clearer using object-orientation.