Total Size of NSMutableArray object

sj wengi picture sj wengi · Oct 4, 2009 · Viewed 71k times · Source

I've got an NSMutableArray that holds a bunch of objects, what I'm trying to figure out is how much memory is the array using. After looking at a couple of places I know about the size of call, and when I make it I get 32 bits (which is the size of the NSMutableArray object it self).

Example code:

NSMutableArray *temp = [[NSMutableArray alloc]init];
[temp addObject:objectxyz];
[temp addObject:objectabc];
[temp addObject:object123];

now I want to know the size :)

Answer

Sophie Alpert picture Sophie Alpert · Oct 4, 2009

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.