Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

ios - Total Size of NSMutableArray object

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 :)

question from:https://stackoverflow.com/questions/1515538/total-size-of-nsmutablearray-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...