ios - Why the NSNumber *test = [NSNumber numberWithInt:i] does not add memory footprint in a for loop? -


i trying reproduce huge memory footprint in loop.for example, in loop below, if there not autorelease pool in it. cause peak memory footprint.

for(int i=0; i< 500000; i++){     nsnumber *test = [nsnumber numberwithint:i]; } 

because expression [nsnumber numberwithint:i] return autorelease object , if no autorelease in loop, autoreleased objects released once, cause peak memory footprint.
tested in xcode6, result not reproduced. used totalsize += malloc_size((__bridge const void *) test); calculate total size of objects, got totalsize = 0 result.
can reproduce huge memory footprint code [nsstring stringwithformat:@"%d ", i];.
can 1 explain question, in advance.

small nsnumbers (those fit in 60 bit) stored tagged pointers. it's actual 64-bit pointer value carries numeric value, there's no heap allocation going on. done transparently obj-c runtime. more on topic: https://mikeash.com/pyblog/friday-qa-2012-07-27-lets-build-tagged-pointers.html

short nsstring's stored tagged pointers well. see mike ash's excellent article on tagged pointer strings: https://mikeash.com/pyblog/friday-qa-2015-07-31-tagged-pointer-strings.html


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -