In short, you cannot. At least this is not useful.
Almost every class will have any number of distributions that are not directly credited to the instance distribution. In addition, many classes - NSDictionary , NSArray , NSString - are actually part of the cluster of classes, and thus, what is actually allocated is a subclass. Finally, for different collection classes and data, the size of the associated distributions will vary greatly depending on their contents. Some classes are UIImage , NSData , etc. - may contain MB of data that is not actually represented by the distribution of the heap in that they display data from the file system.
Or to summarize, class_getInstanceSize() useless.
Instead, you need to focus on using the memory of your application as a system characteristic of its behavior. The Allocations Instrument can measure your memory usage well and, more importantly, help you determine what is responsible for its consumption.
source share