Total Size of NSMutableArray object

后端 未结 5 1755
盖世英雄少女心
盖世英雄少女心 2021-02-06 21:55

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 cou

5条回答
  •  再見小時候
    2021-02-06 22:19

    Well, you could do something like:

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

    but that doesn't tell you exactly how much storage the array is actually using, since it can grow dynamically and might have more memory at any given time than it needs for just the objects it's pointing to, and of course you'd have to deal with any collections recursively.

    If you're trying to get an idea of how much memory you're using, I suggest digging into the tutorials for Instruments, and getting your head around the memory usage probes it provids.

提交回复
热议问题