Total Size of NSMutableArray object Total Size of NSMutableArray object ios ios

Total Size of NSMutableArray object


To get the number of objects in the array, use

[temp count]

If you want the total memory usage of the array, you'll have to loop through and add up how much memory each object uses, but I don't think that a generic object will give you its size. In general, you shouldn't really have to worry about memory usage, though.


size_t size = class_getInstanceSize([temp Class]);for (id obj in temp) {    size += class_getInstanceSize([obj Class]);}

Note that class_getInstanceSize is declared in /usr/include/objc/runtime.h

Also note that this will only count the memory size of the ivars declared in each class.


There is no direct way to do this since all objects are just stored by reference. There is no concrete notion of "size" in cocoa, especially since objects can have multiple owners which might lead to double counting or other problems.