It may be a basic question but just curious to know the answer. How much memory will be occupied when we are creating each variable like int, NSString, NSDictionary, NSData etc. in our iOS Obj C program. I hope, it will be similar to C program based on the size of the data type (or) differently ?
Thank you!
In short, you can't. At least not in a useful fashion.
Just about every class will have any number of allocations that are not directly credited to the instance's allocation directly. As well, many classes -- NSDictionary
, NSArray
, NSString
-- are actually a part of a class cluster and, thus, what is actually allocated is a subclass. Finally, for the various collection and data classes, the size of the associated allocations are going to vary wildly based on their contents. Some classes -- UIImage
, NSData
, etc -- may contain MBs of data that isn't actually represented by a heap allocation in that they are mapping data from the filesystem.
Or, to summarize, class_getInstanceSize()
is useless.
Instead, you need to focus on the memory usage of your app as a systemic characteristic of its operating behavior. The Allocations Instrument can do a good job of measuring memory usage and, more importantly, help you identify what is responsible for consumption therein.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With