unexplainable malloc call in simple test program : malloc project












0















In a purpose to achieve a school project, I must recode malloc and free functions using only mmap and munmap. I must also compile those functions in a dynamic library (.so file) and use this during the run time.



I am working under mac OS Sierra 10.12.6.



Here is my problem, when I run my very simple program without any malloc call, but using the dynamic library, I can notice some malloc call causing unwanted pages reclaim. The test program I am talking about :



int    main()
{
  int i;
  char *addr;
 
  addr = 0;
  i = 0;
  while (i < 1024) {
    i++;
  }
  return (0);
}


I am trying to learn how to use debugging tools such as strace, but right now I can notice the malloc call simply using a printf inside my own sources. Indeed, when I run the test, the printf is called while no malloc is used. Here is the commands I am using to compile and run everything :



gcc -shared srcs... -o lib_malloc.so
gcc test.c -o test -L ./ -lmalloc
./run.sh ./test


(sources files are already compiled as objects files with -Wall -Wextra -Werror flags before linking at the first line)



Here is run.sh file :



#!/bin/sh
export DYLD_LIBRARY_PATH=.
export DYLD_INSERT_LIBRARIES="lib_malloc.so"
export DYLD_FORCE_FLAT_NAMESPACE=1
$@


I have written a simple memory print function as well. Its purpose is to print every allocated block by my own malloc calling my linked lists and printing it... If I add it to the end of my test.c code, I can see some blocks, like this :



TINY : 0x106f65000
0x106f65052 - 0x106f65072 : 4 octets
0x106f6509c - 0x106f650bc : 4 octets
0x106f650e6 - 0x106f65106 : 4 octets
0x106f65130 - 0x106f6513f : 1 octets
0x106f65169 - 0x106f65196 : 5 octets
0x106f651c0 - 0x106f651fa : 7 octets
0x106f65224 - 0x106f65251 : 5 octets
0x106f6527b - 0x106f652ad : 6 octets
0x106f652d7 - 0x106f65306 : 5 octets
0x106f65330 - 0x106f6533e : 1 octets
0x106f65368 - 0x106f653a8 : 8 octets
0x106f653d2 - 0x106f65403 : 6 octets
0x106f6542d - 0x106f65470 : 8 octets
0x106f6549a - 0x106f654ce : 6 octets
0x106f654f8 - 0x106f6552e : 6 octets
0x106f65558 - 0x106f65564 : 1 octets
0x106f6558e - 0x106f655bb : 5 octets
0x106f655e5 - 0x106f6564b : 12 octets
0x106f65675 - 0x106f65685 : 2 octets
0x106f656af - 0x106f656ef : 8 octets
0x106f65719 - 0x106f65727 : 1 octets
0x106f65751 - 0x106f65851 : 32 octets


We can notice that only "tiny" unwanted spaces have been allocated anyway ...
I might have done a stupid error somewhere or misunderstand something , if someone understand what's happening, it will rescue me so much ! I am searching a solution since days, all my source code for those functions is finish.
I can share more code if needed. Help please !



I apologize for my english, I am currently practicing , thank you :)










share|improve this question

























  • Is the memory allocated constant across runs ? Is it constant when you change your test program ?

    – alamit
    Nov 24 '18 at 22:01











  • the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

    – Hugo Eynard
    Nov 24 '18 at 22:09
















0















In a purpose to achieve a school project, I must recode malloc and free functions using only mmap and munmap. I must also compile those functions in a dynamic library (.so file) and use this during the run time.



I am working under mac OS Sierra 10.12.6.



Here is my problem, when I run my very simple program without any malloc call, but using the dynamic library, I can notice some malloc call causing unwanted pages reclaim. The test program I am talking about :



int    main()
{
  int i;
  char *addr;
 
  addr = 0;
  i = 0;
  while (i < 1024) {
    i++;
  }
  return (0);
}


I am trying to learn how to use debugging tools such as strace, but right now I can notice the malloc call simply using a printf inside my own sources. Indeed, when I run the test, the printf is called while no malloc is used. Here is the commands I am using to compile and run everything :



gcc -shared srcs... -o lib_malloc.so
gcc test.c -o test -L ./ -lmalloc
./run.sh ./test


(sources files are already compiled as objects files with -Wall -Wextra -Werror flags before linking at the first line)



Here is run.sh file :



#!/bin/sh
export DYLD_LIBRARY_PATH=.
export DYLD_INSERT_LIBRARIES="lib_malloc.so"
export DYLD_FORCE_FLAT_NAMESPACE=1
$@


I have written a simple memory print function as well. Its purpose is to print every allocated block by my own malloc calling my linked lists and printing it... If I add it to the end of my test.c code, I can see some blocks, like this :



TINY : 0x106f65000
0x106f65052 - 0x106f65072 : 4 octets
0x106f6509c - 0x106f650bc : 4 octets
0x106f650e6 - 0x106f65106 : 4 octets
0x106f65130 - 0x106f6513f : 1 octets
0x106f65169 - 0x106f65196 : 5 octets
0x106f651c0 - 0x106f651fa : 7 octets
0x106f65224 - 0x106f65251 : 5 octets
0x106f6527b - 0x106f652ad : 6 octets
0x106f652d7 - 0x106f65306 : 5 octets
0x106f65330 - 0x106f6533e : 1 octets
0x106f65368 - 0x106f653a8 : 8 octets
0x106f653d2 - 0x106f65403 : 6 octets
0x106f6542d - 0x106f65470 : 8 octets
0x106f6549a - 0x106f654ce : 6 octets
0x106f654f8 - 0x106f6552e : 6 octets
0x106f65558 - 0x106f65564 : 1 octets
0x106f6558e - 0x106f655bb : 5 octets
0x106f655e5 - 0x106f6564b : 12 octets
0x106f65675 - 0x106f65685 : 2 octets
0x106f656af - 0x106f656ef : 8 octets
0x106f65719 - 0x106f65727 : 1 octets
0x106f65751 - 0x106f65851 : 32 octets


We can notice that only "tiny" unwanted spaces have been allocated anyway ...
I might have done a stupid error somewhere or misunderstand something , if someone understand what's happening, it will rescue me so much ! I am searching a solution since days, all my source code for those functions is finish.
I can share more code if needed. Help please !



I apologize for my english, I am currently practicing , thank you :)










share|improve this question

























  • Is the memory allocated constant across runs ? Is it constant when you change your test program ?

    – alamit
    Nov 24 '18 at 22:01











  • the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

    – Hugo Eynard
    Nov 24 '18 at 22:09














0












0








0








In a purpose to achieve a school project, I must recode malloc and free functions using only mmap and munmap. I must also compile those functions in a dynamic library (.so file) and use this during the run time.



I am working under mac OS Sierra 10.12.6.



Here is my problem, when I run my very simple program without any malloc call, but using the dynamic library, I can notice some malloc call causing unwanted pages reclaim. The test program I am talking about :



int    main()
{
  int i;
  char *addr;
 
  addr = 0;
  i = 0;
  while (i < 1024) {
    i++;
  }
  return (0);
}


I am trying to learn how to use debugging tools such as strace, but right now I can notice the malloc call simply using a printf inside my own sources. Indeed, when I run the test, the printf is called while no malloc is used. Here is the commands I am using to compile and run everything :



gcc -shared srcs... -o lib_malloc.so
gcc test.c -o test -L ./ -lmalloc
./run.sh ./test


(sources files are already compiled as objects files with -Wall -Wextra -Werror flags before linking at the first line)



Here is run.sh file :



#!/bin/sh
export DYLD_LIBRARY_PATH=.
export DYLD_INSERT_LIBRARIES="lib_malloc.so"
export DYLD_FORCE_FLAT_NAMESPACE=1
$@


I have written a simple memory print function as well. Its purpose is to print every allocated block by my own malloc calling my linked lists and printing it... If I add it to the end of my test.c code, I can see some blocks, like this :



TINY : 0x106f65000
0x106f65052 - 0x106f65072 : 4 octets
0x106f6509c - 0x106f650bc : 4 octets
0x106f650e6 - 0x106f65106 : 4 octets
0x106f65130 - 0x106f6513f : 1 octets
0x106f65169 - 0x106f65196 : 5 octets
0x106f651c0 - 0x106f651fa : 7 octets
0x106f65224 - 0x106f65251 : 5 octets
0x106f6527b - 0x106f652ad : 6 octets
0x106f652d7 - 0x106f65306 : 5 octets
0x106f65330 - 0x106f6533e : 1 octets
0x106f65368 - 0x106f653a8 : 8 octets
0x106f653d2 - 0x106f65403 : 6 octets
0x106f6542d - 0x106f65470 : 8 octets
0x106f6549a - 0x106f654ce : 6 octets
0x106f654f8 - 0x106f6552e : 6 octets
0x106f65558 - 0x106f65564 : 1 octets
0x106f6558e - 0x106f655bb : 5 octets
0x106f655e5 - 0x106f6564b : 12 octets
0x106f65675 - 0x106f65685 : 2 octets
0x106f656af - 0x106f656ef : 8 octets
0x106f65719 - 0x106f65727 : 1 octets
0x106f65751 - 0x106f65851 : 32 octets


We can notice that only "tiny" unwanted spaces have been allocated anyway ...
I might have done a stupid error somewhere or misunderstand something , if someone understand what's happening, it will rescue me so much ! I am searching a solution since days, all my source code for those functions is finish.
I can share more code if needed. Help please !



I apologize for my english, I am currently practicing , thank you :)










share|improve this question
















In a purpose to achieve a school project, I must recode malloc and free functions using only mmap and munmap. I must also compile those functions in a dynamic library (.so file) and use this during the run time.



I am working under mac OS Sierra 10.12.6.



Here is my problem, when I run my very simple program without any malloc call, but using the dynamic library, I can notice some malloc call causing unwanted pages reclaim. The test program I am talking about :



int    main()
{
  int i;
  char *addr;
 
  addr = 0;
  i = 0;
  while (i < 1024) {
    i++;
  }
  return (0);
}


I am trying to learn how to use debugging tools such as strace, but right now I can notice the malloc call simply using a printf inside my own sources. Indeed, when I run the test, the printf is called while no malloc is used. Here is the commands I am using to compile and run everything :



gcc -shared srcs... -o lib_malloc.so
gcc test.c -o test -L ./ -lmalloc
./run.sh ./test


(sources files are already compiled as objects files with -Wall -Wextra -Werror flags before linking at the first line)



Here is run.sh file :



#!/bin/sh
export DYLD_LIBRARY_PATH=.
export DYLD_INSERT_LIBRARIES="lib_malloc.so"
export DYLD_FORCE_FLAT_NAMESPACE=1
$@


I have written a simple memory print function as well. Its purpose is to print every allocated block by my own malloc calling my linked lists and printing it... If I add it to the end of my test.c code, I can see some blocks, like this :



TINY : 0x106f65000
0x106f65052 - 0x106f65072 : 4 octets
0x106f6509c - 0x106f650bc : 4 octets
0x106f650e6 - 0x106f65106 : 4 octets
0x106f65130 - 0x106f6513f : 1 octets
0x106f65169 - 0x106f65196 : 5 octets
0x106f651c0 - 0x106f651fa : 7 octets
0x106f65224 - 0x106f65251 : 5 octets
0x106f6527b - 0x106f652ad : 6 octets
0x106f652d7 - 0x106f65306 : 5 octets
0x106f65330 - 0x106f6533e : 1 octets
0x106f65368 - 0x106f653a8 : 8 octets
0x106f653d2 - 0x106f65403 : 6 octets
0x106f6542d - 0x106f65470 : 8 octets
0x106f6549a - 0x106f654ce : 6 octets
0x106f654f8 - 0x106f6552e : 6 octets
0x106f65558 - 0x106f65564 : 1 octets
0x106f6558e - 0x106f655bb : 5 octets
0x106f655e5 - 0x106f6564b : 12 octets
0x106f65675 - 0x106f65685 : 2 octets
0x106f656af - 0x106f656ef : 8 octets
0x106f65719 - 0x106f65727 : 1 octets
0x106f65751 - 0x106f65851 : 32 octets


We can notice that only "tiny" unwanted spaces have been allocated anyway ...
I might have done a stupid error somewhere or misunderstand something , if someone understand what's happening, it will rescue me so much ! I am searching a solution since days, all my source code for those functions is finish.
I can share more code if needed. Help please !



I apologize for my english, I am currently practicing , thank you :)







c memory malloc dynamic-library dyld






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 22:13







Hugo Eynard

















asked Nov 24 '18 at 21:52









Hugo EynardHugo Eynard

62




62













  • Is the memory allocated constant across runs ? Is it constant when you change your test program ?

    – alamit
    Nov 24 '18 at 22:01











  • the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

    – Hugo Eynard
    Nov 24 '18 at 22:09



















  • Is the memory allocated constant across runs ? Is it constant when you change your test program ?

    – alamit
    Nov 24 '18 at 22:01











  • the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

    – Hugo Eynard
    Nov 24 '18 at 22:09

















Is the memory allocated constant across runs ? Is it constant when you change your test program ?

– alamit
Nov 24 '18 at 22:01





Is the memory allocated constant across runs ? Is it constant when you change your test program ?

– alamit
Nov 24 '18 at 22:01













the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

– Hugo Eynard
Nov 24 '18 at 22:09





the location that my function is printing is different after each runs, but the sizes and number of blocks allocated is constant , I mean I always get this 4o 4o 4o ..32o list of blocks. I did a test as well with malloc and free calls, my malloc add news blocks without any problem but free segfault because those blocks seems not to have initialized the prev pointer of my structure block ...

– Hugo Eynard
Nov 24 '18 at 22:09












1 Answer
1






active

oldest

votes


















0














By inserting a call to sleep(30) into your sample program and running it with the system allocator with MallocStackLogging=YES set in the environment, we can use malloc_history to see stack traces for the unexpected allocation events:



mrowe@apollo:~$ malloc_history test -callTree
malloc_history Report Version: 2.0
Process: test [16546]
Path: /Users/mrowe/test
Load Address: 0x10d108000
Identifier: test
Version: 0
Code Type: X86-64
Parent Process: bash [15909]

Date/Time: 2018-12-04 23:45:21.610 -0800
Launch Time: 2018-12-04 23:45:20.309 -0800
OS Version: Mac OS X 10.14 (18A389)
Report Version: 7
Analysis Tool: /Applications/Xcode-10.0.app/Contents/Developer/usr/bin/malloc_history
Analysis Tool Version: Xcode 10.0 (10A255)

Physical footprint: 884K
Physical footprint (peak): 884K
----

Call graph:
157 (13.0K) Thread_114575c1
157 (13.0K) _dyld_start (in dyld) + 54 [0x1113a2036]
157 (13.0K) dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in dyld) + 1154 [0x1113a24f6]
157 (13.0K) dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in dyld) + 6237 [0x1113a878f]
157 (13.0K) dyld::initializeMainExecutable() (in dyld) + 199 [0x1113a3774]
157 (13.0K) ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in dyld) + 74 [0x1113b42e8]
157 (13.0K) ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 134 [0x1113b4254]
157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 249 [0x1113b506d]
157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 358 [0x1113b50da]
157 (13.0K) ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in dyld) + 40 [0x1113b9ec6]
157 (13.0K) ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in dyld) + 518 [0x1113b9cc8]
130 (11.2K) libSystem_initializer (in libSystem.B.dylib) + 121 [0x7fff62b299c5]
+ 130 (11.2K) libdispatch_init (in libdispatch.dylib) + 282 [0x7fff656703a7]
+ 130 (11.2K) _os_object_init (in libdispatch.dylib) + 13 [0x7fff656645c4]
+ 130 (11.2K) _objc_init (in libobjc.A.dylib) + 116 [0x7fff645d0c34]
+ 130 (11.2K) _dyld_objc_notify_register (in libdyld.dylib) + 113 [0x7fff6569e647]
+ 130 (11.2K) dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in dyld) + 63 [0x1113a669a]
+ 130 (11.2K) dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in dyld) + 1477 [0x1113a6571]
+ 130 (11.2K) map_images (in libobjc.A.dylib) + 68 [0x7fff645e5279]
+ 130 (11.2K) map_images_nolock (in libobjc.A.dylib) + 1197 [0x7fff645d1473]
+ 116 (7.62K) _read_images (in libobjc.A.dylib) + 2468 [0x7fff645d2c66]
+ ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
+ ! : 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 16 (1.38K) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
+ ! 8 (896 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
+ ! | 6 (768 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
+ ! | + 5 (704 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
+ ! | + ! 4 (640 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 1398 [0x7fff645d4a3a]
+ ! | + ! : 4 (640 bytes) unattachedCategoriesForClass(objc_class*, bool) (in libobjc.A.dylib) + 53 [0x7fff645d5731]
+ ! | + ! : 4 (640 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
+ ! | + ! : 1 (528 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
+ ! | + ! : | 1 (528 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! | + ! : 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 214 [0x7fff645d32f4]
+ ! | + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
+ ! | + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
+ ! | + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
+ ! | + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
+ ! | + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! | + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! | + ! 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! | + ! 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! | + ! 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! | + 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
+ ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! | 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! | 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! | 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! | 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
+ ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
+ ! 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ 1 (2.50K) _read_images (in libobjc.A.dylib) + 1845 [0x7fff645d29f7]
+ ! 1 (2.50K) NXMapInsert (in libobjc.A.dylib) + 285 [0x7fff645d42b5]
+ ! 1 (2.50K) _NXMapRehash(_NXMapTable*) (in libobjc.A.dylib) + 84 [0x7fff645d43fe]
+ ! 1 (2.50K) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ 1 (736 bytes) _read_images (in libobjc.A.dylib) + 396 [0x7fff645d244e]
+ ! 1 (736 bytes) arc4random_buf (in libsystem_c.dylib) + 37 [0x7fff65723479]
+ ! 1 (736 bytes) arc4_init (in libsystem_c.dylib) + 109 [0x7fff6572331d]
+ ! 1 (736 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! 1 (736 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ 7 (256 bytes) _read_images (in libobjc.A.dylib) + 505 [0x7fff645d24bb]
+ ! 7 (256 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
+ ! 4 (144 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 79 [0x7fff645d326d]
+ ! : 4 (144 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
+ ! : 1 (48 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
+ ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
+ ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
+ ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
+ ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 72 [0x7fff645d33e3]
+ ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
+ ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
+ ! : 1 (48 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
+ ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
+ ! 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ 4 (112 bytes) _read_images (in libobjc.A.dylib) + 540 [0x7fff645d24de]
+ ! 4 (112 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
+ ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
+ ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
+ ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
+ ! : 1 (32 bytes) NXHashInsert (in libobjc.A.dylib) + 175 [0x7fff645d3712]
+ ! : 1 (32 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 1 (16 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 402 [0x7fff645d352d]
+ ! 1 (16 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ 1 (32 bytes) _read_images (in libobjc.A.dylib) + 1711 [0x7fff645d2971]
+ 1 (32 bytes) protocols() (in libobjc.A.dylib) + 47 [0x7fff645d3d33]
+ 1 (32 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
+ 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
+ 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
26 (1.61K) libSystem_initializer (in libSystem.B.dylib) + 126 [0x7fff62b299ca]
+ 19 (1.16K) _libxpc_initializer (in libxpc.dylib) + 983 [0x7fff658daa21]
+ ! 18 (992 bytes) _xpc_collect_environment (in libxpc.dylib) + 96 [0x7fff658dafa0]
+ ! : 12 (656 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 24 [0x7fff658db123]
+ ! : | 6 (368 bytes) xpc_string_create (in libxpc.dylib) + 11 [0x7fff658db151]
+ ! : | + 6 (368 bytes) strdup (in libsystem_c.dylib) + 32 [0x7fff6575867e]
+ ! : | + 6 (368 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : | + 6 (368 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! : | 6 (288 bytes) xpc_string_create (in libxpc.dylib) + 38 [0x7fff658db16c]
+ ! : | 6 (288 bytes) _xpc_string_create (in libxpc.dylib) + 30 [0x7fff658f5c14]
+ ! : | 6 (288 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
+ ! : | 6 (288 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
+ ! : | 6 (288 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! : | 6 (288 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! : 6 (336 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 41 [0x7fff658db134]
+ ! : 6 (336 bytes) _xpc_dictionary_insert (in libxpc.dylib) + 371 [0x7fff658db3ae]
+ ! : 6 (336 bytes) _xpc_malloc (in libxpc.dylib) + 47 [0x7fff658db4f7]
+ ! : 6 (336 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : 6 (336 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (192 bytes) _xpc_collect_environment (in libxpc.dylib) + 45 [0x7fff658daf6d]
+ ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
+ ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
+ ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
+ ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ 1 (192 bytes) _libxpc_initializer (in libxpc.dylib) + 988 [0x7fff658daa26]
+ ! 1 (192 bytes) _xpc_collect_images (in libxpc.dylib) + 65 [0x7fff658db5e0]
+ ! 1 (192 bytes) dyld::registerLoadCallback(void (*)(mach_header const*, char const*, bool)) (in dyld) + 265 [0x1113a58b9]
+ ! 1 (192 bytes) _xpc_dyld_image_callback (in libxpc.dylib) + 89 [0x7fff658db6bf]
+ ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
+ ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
+ ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
+ ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ 2 (112 bytes) _libxpc_initializer (in libxpc.dylib) + 142 [0x7fff658da6d8]
+ ! 1 (64 bytes) xpc_array_create (in libxpc.dylib) + 71 [0x7fff658dac3f]
+ ! : 1 (64 bytes) _xpc_calloc (in libxpc.dylib) + 52 [0x7fff658dacb6]
+ ! : 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! : 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ ! 1 (48 bytes) xpc_array_create (in libxpc.dylib) + 46 [0x7fff658dac26]
+ ! 1 (48 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
+ ! 1 (48 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
+ ! 1 (48 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ ! 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
+ 3 (96 bytes) _libxpc_initializer (in libxpc.dylib) + 1139 [0x7fff658daabd]
+ ! 2 (80 bytes) setenv (in libsystem_c.dylib) + 94 [0x7fff657614d9]
+ ! : 1 (64 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 35 [0x7fff65760dfb]
+ ! : | 1 (64 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : | 1 (64 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! : 1 (16 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 17 [0x7fff65760de9]
+ ! : 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! : 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ ! 1 (16 bytes) setenv (in libsystem_c.dylib) + 140 [0x7fff65761507]
+ ! 1 (16 bytes) __setenv_locked (in libsystem_c.dylib) + 625 [0x7fff657610fe]
+ ! 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
+ ! 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
+ 1 (64 bytes) _libxpc_initializer (in libxpc.dylib) + 978 [0x7fff658daa1c]
+ 1 (64 bytes) _xpc_create_bootstrap_pipe (in libxpc.dylib) + 45 [0x7fff658dae82]
+ 1 (64 bytes) _xpc_pipe_create (in libxpc.dylib) + 64 [0x7fff658eecd8]
+ 1 (64 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
+ 1 (64 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
+ 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
+ 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
1 (128 bytes) libSystem_initializer (in libSystem.B.dylib) + 131 [0x7fff62b299cf]
1 (128 bytes) _libtrace_init (in libsystem_trace.dylib) + 250 [0x7fff658bda54]
1 (128 bytes) _dispatch_lane_create_with_target (in libdispatch.dylib) + 373 [0x7fff65669b12]
1 (128 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
1 (128 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
1 (128 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
1 (128 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]


This output makes clear that the allocations are coming from various static initializers in libSystem.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462682%2funexplainable-malloc-call-in-simple-test-program-malloc-project%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    By inserting a call to sleep(30) into your sample program and running it with the system allocator with MallocStackLogging=YES set in the environment, we can use malloc_history to see stack traces for the unexpected allocation events:



    mrowe@apollo:~$ malloc_history test -callTree
    malloc_history Report Version: 2.0
    Process: test [16546]
    Path: /Users/mrowe/test
    Load Address: 0x10d108000
    Identifier: test
    Version: 0
    Code Type: X86-64
    Parent Process: bash [15909]

    Date/Time: 2018-12-04 23:45:21.610 -0800
    Launch Time: 2018-12-04 23:45:20.309 -0800
    OS Version: Mac OS X 10.14 (18A389)
    Report Version: 7
    Analysis Tool: /Applications/Xcode-10.0.app/Contents/Developer/usr/bin/malloc_history
    Analysis Tool Version: Xcode 10.0 (10A255)

    Physical footprint: 884K
    Physical footprint (peak): 884K
    ----

    Call graph:
    157 (13.0K) Thread_114575c1
    157 (13.0K) _dyld_start (in dyld) + 54 [0x1113a2036]
    157 (13.0K) dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in dyld) + 1154 [0x1113a24f6]
    157 (13.0K) dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in dyld) + 6237 [0x1113a878f]
    157 (13.0K) dyld::initializeMainExecutable() (in dyld) + 199 [0x1113a3774]
    157 (13.0K) ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in dyld) + 74 [0x1113b42e8]
    157 (13.0K) ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 134 [0x1113b4254]
    157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 249 [0x1113b506d]
    157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 358 [0x1113b50da]
    157 (13.0K) ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in dyld) + 40 [0x1113b9ec6]
    157 (13.0K) ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in dyld) + 518 [0x1113b9cc8]
    130 (11.2K) libSystem_initializer (in libSystem.B.dylib) + 121 [0x7fff62b299c5]
    + 130 (11.2K) libdispatch_init (in libdispatch.dylib) + 282 [0x7fff656703a7]
    + 130 (11.2K) _os_object_init (in libdispatch.dylib) + 13 [0x7fff656645c4]
    + 130 (11.2K) _objc_init (in libobjc.A.dylib) + 116 [0x7fff645d0c34]
    + 130 (11.2K) _dyld_objc_notify_register (in libdyld.dylib) + 113 [0x7fff6569e647]
    + 130 (11.2K) dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in dyld) + 63 [0x1113a669a]
    + 130 (11.2K) dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in dyld) + 1477 [0x1113a6571]
    + 130 (11.2K) map_images (in libobjc.A.dylib) + 68 [0x7fff645e5279]
    + 130 (11.2K) map_images_nolock (in libobjc.A.dylib) + 1197 [0x7fff645d1473]
    + 116 (7.62K) _read_images (in libobjc.A.dylib) + 2468 [0x7fff645d2c66]
    + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
    + ! : 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 16 (1.38K) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
    + ! 8 (896 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
    + ! | 6 (768 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
    + ! | + 5 (704 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
    + ! | + ! 4 (640 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 1398 [0x7fff645d4a3a]
    + ! | + ! : 4 (640 bytes) unattachedCategoriesForClass(objc_class*, bool) (in libobjc.A.dylib) + 53 [0x7fff645d5731]
    + ! | + ! : 4 (640 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
    + ! | + ! : 1 (528 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
    + ! | + ! : | 1 (528 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! | + ! : 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 214 [0x7fff645d32f4]
    + ! | + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
    + ! | + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
    + ! | + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
    + ! | + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
    + ! | + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! | + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! | + ! 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! | + ! 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! | + ! 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! | + 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
    + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! | 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! | 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! | 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! | 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
    + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
    + ! 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + 1 (2.50K) _read_images (in libobjc.A.dylib) + 1845 [0x7fff645d29f7]
    + ! 1 (2.50K) NXMapInsert (in libobjc.A.dylib) + 285 [0x7fff645d42b5]
    + ! 1 (2.50K) _NXMapRehash(_NXMapTable*) (in libobjc.A.dylib) + 84 [0x7fff645d43fe]
    + ! 1 (2.50K) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + 1 (736 bytes) _read_images (in libobjc.A.dylib) + 396 [0x7fff645d244e]
    + ! 1 (736 bytes) arc4random_buf (in libsystem_c.dylib) + 37 [0x7fff65723479]
    + ! 1 (736 bytes) arc4_init (in libsystem_c.dylib) + 109 [0x7fff6572331d]
    + ! 1 (736 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! 1 (736 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + 7 (256 bytes) _read_images (in libobjc.A.dylib) + 505 [0x7fff645d24bb]
    + ! 7 (256 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
    + ! 4 (144 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 79 [0x7fff645d326d]
    + ! : 4 (144 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
    + ! : 1 (48 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
    + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
    + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
    + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
    + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 72 [0x7fff645d33e3]
    + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
    + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
    + ! : 1 (48 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
    + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
    + ! 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + 4 (112 bytes) _read_images (in libobjc.A.dylib) + 540 [0x7fff645d24de]
    + ! 4 (112 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
    + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
    + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
    + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
    + ! : 1 (32 bytes) NXHashInsert (in libobjc.A.dylib) + 175 [0x7fff645d3712]
    + ! : 1 (32 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 1 (16 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 402 [0x7fff645d352d]
    + ! 1 (16 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + 1 (32 bytes) _read_images (in libobjc.A.dylib) + 1711 [0x7fff645d2971]
    + 1 (32 bytes) protocols() (in libobjc.A.dylib) + 47 [0x7fff645d3d33]
    + 1 (32 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
    + 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
    + 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    26 (1.61K) libSystem_initializer (in libSystem.B.dylib) + 126 [0x7fff62b299ca]
    + 19 (1.16K) _libxpc_initializer (in libxpc.dylib) + 983 [0x7fff658daa21]
    + ! 18 (992 bytes) _xpc_collect_environment (in libxpc.dylib) + 96 [0x7fff658dafa0]
    + ! : 12 (656 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 24 [0x7fff658db123]
    + ! : | 6 (368 bytes) xpc_string_create (in libxpc.dylib) + 11 [0x7fff658db151]
    + ! : | + 6 (368 bytes) strdup (in libsystem_c.dylib) + 32 [0x7fff6575867e]
    + ! : | + 6 (368 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : | + 6 (368 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! : | 6 (288 bytes) xpc_string_create (in libxpc.dylib) + 38 [0x7fff658db16c]
    + ! : | 6 (288 bytes) _xpc_string_create (in libxpc.dylib) + 30 [0x7fff658f5c14]
    + ! : | 6 (288 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    + ! : | 6 (288 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    + ! : | 6 (288 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! : | 6 (288 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! : 6 (336 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 41 [0x7fff658db134]
    + ! : 6 (336 bytes) _xpc_dictionary_insert (in libxpc.dylib) + 371 [0x7fff658db3ae]
    + ! : 6 (336 bytes) _xpc_malloc (in libxpc.dylib) + 47 [0x7fff658db4f7]
    + ! : 6 (336 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : 6 (336 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (192 bytes) _xpc_collect_environment (in libxpc.dylib) + 45 [0x7fff658daf6d]
    + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
    + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + 1 (192 bytes) _libxpc_initializer (in libxpc.dylib) + 988 [0x7fff658daa26]
    + ! 1 (192 bytes) _xpc_collect_images (in libxpc.dylib) + 65 [0x7fff658db5e0]
    + ! 1 (192 bytes) dyld::registerLoadCallback(void (*)(mach_header const*, char const*, bool)) (in dyld) + 265 [0x1113a58b9]
    + ! 1 (192 bytes) _xpc_dyld_image_callback (in libxpc.dylib) + 89 [0x7fff658db6bf]
    + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
    + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + 2 (112 bytes) _libxpc_initializer (in libxpc.dylib) + 142 [0x7fff658da6d8]
    + ! 1 (64 bytes) xpc_array_create (in libxpc.dylib) + 71 [0x7fff658dac3f]
    + ! : 1 (64 bytes) _xpc_calloc (in libxpc.dylib) + 52 [0x7fff658dacb6]
    + ! : 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! : 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + ! 1 (48 bytes) xpc_array_create (in libxpc.dylib) + 46 [0x7fff658dac26]
    + ! 1 (48 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    + ! 1 (48 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    + ! 1 (48 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + ! 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    + 3 (96 bytes) _libxpc_initializer (in libxpc.dylib) + 1139 [0x7fff658daabd]
    + ! 2 (80 bytes) setenv (in libsystem_c.dylib) + 94 [0x7fff657614d9]
    + ! : 1 (64 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 35 [0x7fff65760dfb]
    + ! : | 1 (64 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : | 1 (64 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! : 1 (16 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 17 [0x7fff65760de9]
    + ! : 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! : 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + ! 1 (16 bytes) setenv (in libsystem_c.dylib) + 140 [0x7fff65761507]
    + ! 1 (16 bytes) __setenv_locked (in libsystem_c.dylib) + 625 [0x7fff657610fe]
    + ! 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
    + ! 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
    + 1 (64 bytes) _libxpc_initializer (in libxpc.dylib) + 978 [0x7fff658daa1c]
    + 1 (64 bytes) _xpc_create_bootstrap_pipe (in libxpc.dylib) + 45 [0x7fff658dae82]
    + 1 (64 bytes) _xpc_pipe_create (in libxpc.dylib) + 64 [0x7fff658eecd8]
    + 1 (64 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    + 1 (64 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
    1 (128 bytes) libSystem_initializer (in libSystem.B.dylib) + 131 [0x7fff62b299cf]
    1 (128 bytes) _libtrace_init (in libsystem_trace.dylib) + 250 [0x7fff658bda54]
    1 (128 bytes) _dispatch_lane_create_with_target (in libdispatch.dylib) + 373 [0x7fff65669b12]
    1 (128 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
    1 (128 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
    1 (128 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
    1 (128 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]


    This output makes clear that the allocations are coming from various static initializers in libSystem.






    share|improve this answer




























      0














      By inserting a call to sleep(30) into your sample program and running it with the system allocator with MallocStackLogging=YES set in the environment, we can use malloc_history to see stack traces for the unexpected allocation events:



      mrowe@apollo:~$ malloc_history test -callTree
      malloc_history Report Version: 2.0
      Process: test [16546]
      Path: /Users/mrowe/test
      Load Address: 0x10d108000
      Identifier: test
      Version: 0
      Code Type: X86-64
      Parent Process: bash [15909]

      Date/Time: 2018-12-04 23:45:21.610 -0800
      Launch Time: 2018-12-04 23:45:20.309 -0800
      OS Version: Mac OS X 10.14 (18A389)
      Report Version: 7
      Analysis Tool: /Applications/Xcode-10.0.app/Contents/Developer/usr/bin/malloc_history
      Analysis Tool Version: Xcode 10.0 (10A255)

      Physical footprint: 884K
      Physical footprint (peak): 884K
      ----

      Call graph:
      157 (13.0K) Thread_114575c1
      157 (13.0K) _dyld_start (in dyld) + 54 [0x1113a2036]
      157 (13.0K) dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in dyld) + 1154 [0x1113a24f6]
      157 (13.0K) dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in dyld) + 6237 [0x1113a878f]
      157 (13.0K) dyld::initializeMainExecutable() (in dyld) + 199 [0x1113a3774]
      157 (13.0K) ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in dyld) + 74 [0x1113b42e8]
      157 (13.0K) ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 134 [0x1113b4254]
      157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 249 [0x1113b506d]
      157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 358 [0x1113b50da]
      157 (13.0K) ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in dyld) + 40 [0x1113b9ec6]
      157 (13.0K) ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in dyld) + 518 [0x1113b9cc8]
      130 (11.2K) libSystem_initializer (in libSystem.B.dylib) + 121 [0x7fff62b299c5]
      + 130 (11.2K) libdispatch_init (in libdispatch.dylib) + 282 [0x7fff656703a7]
      + 130 (11.2K) _os_object_init (in libdispatch.dylib) + 13 [0x7fff656645c4]
      + 130 (11.2K) _objc_init (in libobjc.A.dylib) + 116 [0x7fff645d0c34]
      + 130 (11.2K) _dyld_objc_notify_register (in libdyld.dylib) + 113 [0x7fff6569e647]
      + 130 (11.2K) dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in dyld) + 63 [0x1113a669a]
      + 130 (11.2K) dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in dyld) + 1477 [0x1113a6571]
      + 130 (11.2K) map_images (in libobjc.A.dylib) + 68 [0x7fff645e5279]
      + 130 (11.2K) map_images_nolock (in libobjc.A.dylib) + 1197 [0x7fff645d1473]
      + 116 (7.62K) _read_images (in libobjc.A.dylib) + 2468 [0x7fff645d2c66]
      + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
      + ! : 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 16 (1.38K) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
      + ! 8 (896 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
      + ! | 6 (768 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
      + ! | + 5 (704 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
      + ! | + ! 4 (640 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 1398 [0x7fff645d4a3a]
      + ! | + ! : 4 (640 bytes) unattachedCategoriesForClass(objc_class*, bool) (in libobjc.A.dylib) + 53 [0x7fff645d5731]
      + ! | + ! : 4 (640 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
      + ! | + ! : 1 (528 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
      + ! | + ! : | 1 (528 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! | + ! : 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 214 [0x7fff645d32f4]
      + ! | + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
      + ! | + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
      + ! | + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
      + ! | + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
      + ! | + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! | + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! | + ! 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! | + ! 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! | + ! 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! | + 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
      + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! | 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! | 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! | 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! | 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
      + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
      + ! 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + 1 (2.50K) _read_images (in libobjc.A.dylib) + 1845 [0x7fff645d29f7]
      + ! 1 (2.50K) NXMapInsert (in libobjc.A.dylib) + 285 [0x7fff645d42b5]
      + ! 1 (2.50K) _NXMapRehash(_NXMapTable*) (in libobjc.A.dylib) + 84 [0x7fff645d43fe]
      + ! 1 (2.50K) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + 1 (736 bytes) _read_images (in libobjc.A.dylib) + 396 [0x7fff645d244e]
      + ! 1 (736 bytes) arc4random_buf (in libsystem_c.dylib) + 37 [0x7fff65723479]
      + ! 1 (736 bytes) arc4_init (in libsystem_c.dylib) + 109 [0x7fff6572331d]
      + ! 1 (736 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! 1 (736 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + 7 (256 bytes) _read_images (in libobjc.A.dylib) + 505 [0x7fff645d24bb]
      + ! 7 (256 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
      + ! 4 (144 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 79 [0x7fff645d326d]
      + ! : 4 (144 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
      + ! : 1 (48 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
      + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
      + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
      + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
      + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 72 [0x7fff645d33e3]
      + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
      + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
      + ! : 1 (48 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
      + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
      + ! 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + 4 (112 bytes) _read_images (in libobjc.A.dylib) + 540 [0x7fff645d24de]
      + ! 4 (112 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
      + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
      + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
      + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
      + ! : 1 (32 bytes) NXHashInsert (in libobjc.A.dylib) + 175 [0x7fff645d3712]
      + ! : 1 (32 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 1 (16 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 402 [0x7fff645d352d]
      + ! 1 (16 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + 1 (32 bytes) _read_images (in libobjc.A.dylib) + 1711 [0x7fff645d2971]
      + 1 (32 bytes) protocols() (in libobjc.A.dylib) + 47 [0x7fff645d3d33]
      + 1 (32 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
      + 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
      + 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      26 (1.61K) libSystem_initializer (in libSystem.B.dylib) + 126 [0x7fff62b299ca]
      + 19 (1.16K) _libxpc_initializer (in libxpc.dylib) + 983 [0x7fff658daa21]
      + ! 18 (992 bytes) _xpc_collect_environment (in libxpc.dylib) + 96 [0x7fff658dafa0]
      + ! : 12 (656 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 24 [0x7fff658db123]
      + ! : | 6 (368 bytes) xpc_string_create (in libxpc.dylib) + 11 [0x7fff658db151]
      + ! : | + 6 (368 bytes) strdup (in libsystem_c.dylib) + 32 [0x7fff6575867e]
      + ! : | + 6 (368 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : | + 6 (368 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! : | 6 (288 bytes) xpc_string_create (in libxpc.dylib) + 38 [0x7fff658db16c]
      + ! : | 6 (288 bytes) _xpc_string_create (in libxpc.dylib) + 30 [0x7fff658f5c14]
      + ! : | 6 (288 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      + ! : | 6 (288 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      + ! : | 6 (288 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! : | 6 (288 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! : 6 (336 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 41 [0x7fff658db134]
      + ! : 6 (336 bytes) _xpc_dictionary_insert (in libxpc.dylib) + 371 [0x7fff658db3ae]
      + ! : 6 (336 bytes) _xpc_malloc (in libxpc.dylib) + 47 [0x7fff658db4f7]
      + ! : 6 (336 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : 6 (336 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (192 bytes) _xpc_collect_environment (in libxpc.dylib) + 45 [0x7fff658daf6d]
      + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
      + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + 1 (192 bytes) _libxpc_initializer (in libxpc.dylib) + 988 [0x7fff658daa26]
      + ! 1 (192 bytes) _xpc_collect_images (in libxpc.dylib) + 65 [0x7fff658db5e0]
      + ! 1 (192 bytes) dyld::registerLoadCallback(void (*)(mach_header const*, char const*, bool)) (in dyld) + 265 [0x1113a58b9]
      + ! 1 (192 bytes) _xpc_dyld_image_callback (in libxpc.dylib) + 89 [0x7fff658db6bf]
      + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
      + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + 2 (112 bytes) _libxpc_initializer (in libxpc.dylib) + 142 [0x7fff658da6d8]
      + ! 1 (64 bytes) xpc_array_create (in libxpc.dylib) + 71 [0x7fff658dac3f]
      + ! : 1 (64 bytes) _xpc_calloc (in libxpc.dylib) + 52 [0x7fff658dacb6]
      + ! : 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! : 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + ! 1 (48 bytes) xpc_array_create (in libxpc.dylib) + 46 [0x7fff658dac26]
      + ! 1 (48 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      + ! 1 (48 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      + ! 1 (48 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + ! 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      + 3 (96 bytes) _libxpc_initializer (in libxpc.dylib) + 1139 [0x7fff658daabd]
      + ! 2 (80 bytes) setenv (in libsystem_c.dylib) + 94 [0x7fff657614d9]
      + ! : 1 (64 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 35 [0x7fff65760dfb]
      + ! : | 1 (64 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : | 1 (64 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! : 1 (16 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 17 [0x7fff65760de9]
      + ! : 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! : 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + ! 1 (16 bytes) setenv (in libsystem_c.dylib) + 140 [0x7fff65761507]
      + ! 1 (16 bytes) __setenv_locked (in libsystem_c.dylib) + 625 [0x7fff657610fe]
      + ! 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
      + ! 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
      + 1 (64 bytes) _libxpc_initializer (in libxpc.dylib) + 978 [0x7fff658daa1c]
      + 1 (64 bytes) _xpc_create_bootstrap_pipe (in libxpc.dylib) + 45 [0x7fff658dae82]
      + 1 (64 bytes) _xpc_pipe_create (in libxpc.dylib) + 64 [0x7fff658eecd8]
      + 1 (64 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      + 1 (64 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
      1 (128 bytes) libSystem_initializer (in libSystem.B.dylib) + 131 [0x7fff62b299cf]
      1 (128 bytes) _libtrace_init (in libsystem_trace.dylib) + 250 [0x7fff658bda54]
      1 (128 bytes) _dispatch_lane_create_with_target (in libdispatch.dylib) + 373 [0x7fff65669b12]
      1 (128 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
      1 (128 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
      1 (128 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
      1 (128 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]


      This output makes clear that the allocations are coming from various static initializers in libSystem.






      share|improve this answer


























        0












        0








        0







        By inserting a call to sleep(30) into your sample program and running it with the system allocator with MallocStackLogging=YES set in the environment, we can use malloc_history to see stack traces for the unexpected allocation events:



        mrowe@apollo:~$ malloc_history test -callTree
        malloc_history Report Version: 2.0
        Process: test [16546]
        Path: /Users/mrowe/test
        Load Address: 0x10d108000
        Identifier: test
        Version: 0
        Code Type: X86-64
        Parent Process: bash [15909]

        Date/Time: 2018-12-04 23:45:21.610 -0800
        Launch Time: 2018-12-04 23:45:20.309 -0800
        OS Version: Mac OS X 10.14 (18A389)
        Report Version: 7
        Analysis Tool: /Applications/Xcode-10.0.app/Contents/Developer/usr/bin/malloc_history
        Analysis Tool Version: Xcode 10.0 (10A255)

        Physical footprint: 884K
        Physical footprint (peak): 884K
        ----

        Call graph:
        157 (13.0K) Thread_114575c1
        157 (13.0K) _dyld_start (in dyld) + 54 [0x1113a2036]
        157 (13.0K) dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in dyld) + 1154 [0x1113a24f6]
        157 (13.0K) dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in dyld) + 6237 [0x1113a878f]
        157 (13.0K) dyld::initializeMainExecutable() (in dyld) + 199 [0x1113a3774]
        157 (13.0K) ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in dyld) + 74 [0x1113b42e8]
        157 (13.0K) ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 134 [0x1113b4254]
        157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 249 [0x1113b506d]
        157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 358 [0x1113b50da]
        157 (13.0K) ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in dyld) + 40 [0x1113b9ec6]
        157 (13.0K) ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in dyld) + 518 [0x1113b9cc8]
        130 (11.2K) libSystem_initializer (in libSystem.B.dylib) + 121 [0x7fff62b299c5]
        + 130 (11.2K) libdispatch_init (in libdispatch.dylib) + 282 [0x7fff656703a7]
        + 130 (11.2K) _os_object_init (in libdispatch.dylib) + 13 [0x7fff656645c4]
        + 130 (11.2K) _objc_init (in libobjc.A.dylib) + 116 [0x7fff645d0c34]
        + 130 (11.2K) _dyld_objc_notify_register (in libdyld.dylib) + 113 [0x7fff6569e647]
        + 130 (11.2K) dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in dyld) + 63 [0x1113a669a]
        + 130 (11.2K) dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in dyld) + 1477 [0x1113a6571]
        + 130 (11.2K) map_images (in libobjc.A.dylib) + 68 [0x7fff645e5279]
        + 130 (11.2K) map_images_nolock (in libobjc.A.dylib) + 1197 [0x7fff645d1473]
        + 116 (7.62K) _read_images (in libobjc.A.dylib) + 2468 [0x7fff645d2c66]
        + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! : 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 16 (1.38K) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! 8 (896 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! | 6 (768 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! | + 5 (704 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! | + ! 4 (640 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 1398 [0x7fff645d4a3a]
        + ! | + ! : 4 (640 bytes) unattachedCategoriesForClass(objc_class*, bool) (in libobjc.A.dylib) + 53 [0x7fff645d5731]
        + ! | + ! : 4 (640 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + ! | + ! : 1 (528 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
        + ! | + ! : | 1 (528 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! : 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 214 [0x7fff645d32f4]
        + ! | + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
        + ! | + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
        + ! | + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + ! | + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
        + ! | + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! | + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + ! 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + ! 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | + 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (2.50K) _read_images (in libobjc.A.dylib) + 1845 [0x7fff645d29f7]
        + ! 1 (2.50K) NXMapInsert (in libobjc.A.dylib) + 285 [0x7fff645d42b5]
        + ! 1 (2.50K) _NXMapRehash(_NXMapTable*) (in libobjc.A.dylib) + 84 [0x7fff645d43fe]
        + ! 1 (2.50K) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 1 (736 bytes) _read_images (in libobjc.A.dylib) + 396 [0x7fff645d244e]
        + ! 1 (736 bytes) arc4random_buf (in libsystem_c.dylib) + 37 [0x7fff65723479]
        + ! 1 (736 bytes) arc4_init (in libsystem_c.dylib) + 109 [0x7fff6572331d]
        + ! 1 (736 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (736 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 7 (256 bytes) _read_images (in libobjc.A.dylib) + 505 [0x7fff645d24bb]
        + ! 7 (256 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + ! 4 (144 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 79 [0x7fff645d326d]
        + ! : 4 (144 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
        + ! : 1 (48 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
        + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
        + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
        + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
        + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 72 [0x7fff645d33e3]
        + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
        + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
        + ! : 1 (48 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
        + ! 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 4 (112 bytes) _read_images (in libobjc.A.dylib) + 540 [0x7fff645d24de]
        + ! 4 (112 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
        + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
        + ! : 1 (32 bytes) NXHashInsert (in libobjc.A.dylib) + 175 [0x7fff645d3712]
        + ! : 1 (32 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 1 (16 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 402 [0x7fff645d352d]
        + ! 1 (16 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (32 bytes) _read_images (in libobjc.A.dylib) + 1711 [0x7fff645d2971]
        + 1 (32 bytes) protocols() (in libobjc.A.dylib) + 47 [0x7fff645d3d33]
        + 1 (32 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        26 (1.61K) libSystem_initializer (in libSystem.B.dylib) + 126 [0x7fff62b299ca]
        + 19 (1.16K) _libxpc_initializer (in libxpc.dylib) + 983 [0x7fff658daa21]
        + ! 18 (992 bytes) _xpc_collect_environment (in libxpc.dylib) + 96 [0x7fff658dafa0]
        + ! : 12 (656 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 24 [0x7fff658db123]
        + ! : | 6 (368 bytes) xpc_string_create (in libxpc.dylib) + 11 [0x7fff658db151]
        + ! : | + 6 (368 bytes) strdup (in libsystem_c.dylib) + 32 [0x7fff6575867e]
        + ! : | + 6 (368 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : | + 6 (368 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : | 6 (288 bytes) xpc_string_create (in libxpc.dylib) + 38 [0x7fff658db16c]
        + ! : | 6 (288 bytes) _xpc_string_create (in libxpc.dylib) + 30 [0x7fff658f5c14]
        + ! : | 6 (288 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! : | 6 (288 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! : | 6 (288 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : | 6 (288 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! : 6 (336 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 41 [0x7fff658db134]
        + ! : 6 (336 bytes) _xpc_dictionary_insert (in libxpc.dylib) + 371 [0x7fff658db3ae]
        + ! : 6 (336 bytes) _xpc_malloc (in libxpc.dylib) + 47 [0x7fff658db4f7]
        + ! : 6 (336 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 6 (336 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (192 bytes) _xpc_collect_environment (in libxpc.dylib) + 45 [0x7fff658daf6d]
        + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
        + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (192 bytes) _libxpc_initializer (in libxpc.dylib) + 988 [0x7fff658daa26]
        + ! 1 (192 bytes) _xpc_collect_images (in libxpc.dylib) + 65 [0x7fff658db5e0]
        + ! 1 (192 bytes) dyld::registerLoadCallback(void (*)(mach_header const*, char const*, bool)) (in dyld) + 265 [0x1113a58b9]
        + ! 1 (192 bytes) _xpc_dyld_image_callback (in libxpc.dylib) + 89 [0x7fff658db6bf]
        + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
        + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 2 (112 bytes) _libxpc_initializer (in libxpc.dylib) + 142 [0x7fff658da6d8]
        + ! 1 (64 bytes) xpc_array_create (in libxpc.dylib) + 71 [0x7fff658dac3f]
        + ! : 1 (64 bytes) _xpc_calloc (in libxpc.dylib) + 52 [0x7fff658dacb6]
        + ! : 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 1 (48 bytes) xpc_array_create (in libxpc.dylib) + 46 [0x7fff658dac26]
        + ! 1 (48 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (48 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (48 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 3 (96 bytes) _libxpc_initializer (in libxpc.dylib) + 1139 [0x7fff658daabd]
        + ! 2 (80 bytes) setenv (in libsystem_c.dylib) + 94 [0x7fff657614d9]
        + ! : 1 (64 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 35 [0x7fff65760dfb]
        + ! : | 1 (64 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : | 1 (64 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (16 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 17 [0x7fff65760de9]
        + ! : 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (16 bytes) setenv (in libsystem_c.dylib) + 140 [0x7fff65761507]
        + ! 1 (16 bytes) __setenv_locked (in libsystem_c.dylib) + 625 [0x7fff657610fe]
        + ! 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 1 (64 bytes) _libxpc_initializer (in libxpc.dylib) + 978 [0x7fff658daa1c]
        + 1 (64 bytes) _xpc_create_bootstrap_pipe (in libxpc.dylib) + 45 [0x7fff658dae82]
        + 1 (64 bytes) _xpc_pipe_create (in libxpc.dylib) + 64 [0x7fff658eecd8]
        + 1 (64 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + 1 (64 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        1 (128 bytes) libSystem_initializer (in libSystem.B.dylib) + 131 [0x7fff62b299cf]
        1 (128 bytes) _libtrace_init (in libsystem_trace.dylib) + 250 [0x7fff658bda54]
        1 (128 bytes) _dispatch_lane_create_with_target (in libdispatch.dylib) + 373 [0x7fff65669b12]
        1 (128 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        1 (128 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        1 (128 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        1 (128 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]


        This output makes clear that the allocations are coming from various static initializers in libSystem.






        share|improve this answer













        By inserting a call to sleep(30) into your sample program and running it with the system allocator with MallocStackLogging=YES set in the environment, we can use malloc_history to see stack traces for the unexpected allocation events:



        mrowe@apollo:~$ malloc_history test -callTree
        malloc_history Report Version: 2.0
        Process: test [16546]
        Path: /Users/mrowe/test
        Load Address: 0x10d108000
        Identifier: test
        Version: 0
        Code Type: X86-64
        Parent Process: bash [15909]

        Date/Time: 2018-12-04 23:45:21.610 -0800
        Launch Time: 2018-12-04 23:45:20.309 -0800
        OS Version: Mac OS X 10.14 (18A389)
        Report Version: 7
        Analysis Tool: /Applications/Xcode-10.0.app/Contents/Developer/usr/bin/malloc_history
        Analysis Tool Version: Xcode 10.0 (10A255)

        Physical footprint: 884K
        Physical footprint (peak): 884K
        ----

        Call graph:
        157 (13.0K) Thread_114575c1
        157 (13.0K) _dyld_start (in dyld) + 54 [0x1113a2036]
        157 (13.0K) dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in dyld) + 1154 [0x1113a24f6]
        157 (13.0K) dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in dyld) + 6237 [0x1113a878f]
        157 (13.0K) dyld::initializeMainExecutable() (in dyld) + 199 [0x1113a3774]
        157 (13.0K) ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in dyld) + 74 [0x1113b42e8]
        157 (13.0K) ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 134 [0x1113b4254]
        157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 249 [0x1113b506d]
        157 (13.0K) ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in dyld) + 358 [0x1113b50da]
        157 (13.0K) ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in dyld) + 40 [0x1113b9ec6]
        157 (13.0K) ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in dyld) + 518 [0x1113b9cc8]
        130 (11.2K) libSystem_initializer (in libSystem.B.dylib) + 121 [0x7fff62b299c5]
        + 130 (11.2K) libdispatch_init (in libdispatch.dylib) + 282 [0x7fff656703a7]
        + 130 (11.2K) _os_object_init (in libdispatch.dylib) + 13 [0x7fff656645c4]
        + 130 (11.2K) _objc_init (in libobjc.A.dylib) + 116 [0x7fff645d0c34]
        + 130 (11.2K) _dyld_objc_notify_register (in libdyld.dylib) + 113 [0x7fff6569e647]
        + 130 (11.2K) dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in dyld) + 63 [0x1113a669a]
        + 130 (11.2K) dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in dyld) + 1477 [0x1113a6571]
        + 130 (11.2K) map_images (in libobjc.A.dylib) + 68 [0x7fff645e5279]
        + 130 (11.2K) map_images_nolock (in libobjc.A.dylib) + 1197 [0x7fff645d1473]
        + 116 (7.62K) _read_images (in libobjc.A.dylib) + 2468 [0x7fff645d2c66]
        + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! : 50 (3.12K) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! : 50 (3.12K) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 50 (3.12K) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 16 (1.38K) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! 8 (896 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! | 6 (768 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 263 [0x7fff645d45cb]
        + ! | + 5 (704 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! | + ! 4 (640 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 1398 [0x7fff645d4a3a]
        + ! | + ! : 4 (640 bytes) unattachedCategoriesForClass(objc_class*, bool) (in libobjc.A.dylib) + 53 [0x7fff645d5731]
        + ! | + ! : 4 (640 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + ! | + ! : 1 (528 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
        + ! | + ! : | 1 (528 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! : 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 214 [0x7fff645d32f4]
        + ! | + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
        + ! | + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
        + ! | + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + ! | + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! : 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
        + ! | + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! | + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! | + ! 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + ! 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + ! 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | + 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! | 1 (64 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! | 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! | 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 287 [0x7fff645d45e3]
        + ! 4 (256 bytes) realizeClass(objc_class*) (in libobjc.A.dylib) + 77 [0x7fff645d4511]
        + ! 4 (256 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 4 (256 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (2.50K) _read_images (in libobjc.A.dylib) + 1845 [0x7fff645d29f7]
        + ! 1 (2.50K) NXMapInsert (in libobjc.A.dylib) + 285 [0x7fff645d42b5]
        + ! 1 (2.50K) _NXMapRehash(_NXMapTable*) (in libobjc.A.dylib) + 84 [0x7fff645d43fe]
        + ! 1 (2.50K) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 1 (736 bytes) _read_images (in libobjc.A.dylib) + 396 [0x7fff645d244e]
        + ! 1 (736 bytes) arc4random_buf (in libsystem_c.dylib) + 37 [0x7fff65723479]
        + ! 1 (736 bytes) arc4_init (in libsystem_c.dylib) + 109 [0x7fff6572331d]
        + ! 1 (736 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (736 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 7 (256 bytes) _read_images (in libobjc.A.dylib) + 505 [0x7fff645d24bb]
        + ! 7 (256 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + ! 4 (144 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 79 [0x7fff645d326d]
        + ! : 4 (144 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
        + ! : 1 (48 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
        + ! : | 1 (48 bytes) NXHashInsert (in libobjc.A.dylib) + 373 [0x7fff645d37d8]
        + ! : | 1 (48 bytes) _NXHashRehashToCapacity (in libobjc.A.dylib) + 101 [0x7fff645d385b]
        + ! : | 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
        + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 72 [0x7fff645d33e3]
        + ! : | 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
        + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (48 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 285 [0x7fff645d333b]
        + ! : 1 (48 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 181 [0x7fff645d32d3]
        + ! 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 4 (112 bytes) _read_images (in libobjc.A.dylib) + 540 [0x7fff645d24de]
        + ! 4 (112 bytes) NXCreateHashTable (in libobjc.A.dylib) + 47 [0x7fff645d3392]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d33c2]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 268 [0x7fff645d34a7]
        + ! : 1 (32 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (32 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 310 [0x7fff645d34d1]
        + ! : 1 (32 bytes) NXHashInsert (in libobjc.A.dylib) + 175 [0x7fff645d3712]
        + ! : 1 (32 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 1 (16 bytes) NXCreateHashTableFromZone (in libobjc.A.dylib) + 402 [0x7fff645d352d]
        + ! 1 (16 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (32 bytes) _read_images (in libobjc.A.dylib) + 1711 [0x7fff645d2971]
        + 1 (32 bytes) protocols() (in libobjc.A.dylib) + 47 [0x7fff645d3d33]
        + 1 (32 bytes) NXCreateMapTable (in libobjc.A.dylib) + 39 [0x7fff645d3217]
        + 1 (32 bytes) NXCreateMapTableFromZone (in libobjc.A.dylib) + 39 [0x7fff645d3245]
        + 1 (32 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        26 (1.61K) libSystem_initializer (in libSystem.B.dylib) + 126 [0x7fff62b299ca]
        + 19 (1.16K) _libxpc_initializer (in libxpc.dylib) + 983 [0x7fff658daa21]
        + ! 18 (992 bytes) _xpc_collect_environment (in libxpc.dylib) + 96 [0x7fff658dafa0]
        + ! : 12 (656 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 24 [0x7fff658db123]
        + ! : | 6 (368 bytes) xpc_string_create (in libxpc.dylib) + 11 [0x7fff658db151]
        + ! : | + 6 (368 bytes) strdup (in libsystem_c.dylib) + 32 [0x7fff6575867e]
        + ! : | + 6 (368 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : | + 6 (368 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : | 6 (288 bytes) xpc_string_create (in libxpc.dylib) + 38 [0x7fff658db16c]
        + ! : | 6 (288 bytes) _xpc_string_create (in libxpc.dylib) + 30 [0x7fff658f5c14]
        + ! : | 6 (288 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! : | 6 (288 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! : | 6 (288 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : | 6 (288 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! : 6 (336 bytes) xpc_dictionary_set_string (in libxpc.dylib) + 41 [0x7fff658db134]
        + ! : 6 (336 bytes) _xpc_dictionary_insert (in libxpc.dylib) + 371 [0x7fff658db3ae]
        + ! : 6 (336 bytes) _xpc_malloc (in libxpc.dylib) + 47 [0x7fff658db4f7]
        + ! : 6 (336 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 6 (336 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (192 bytes) _xpc_collect_environment (in libxpc.dylib) + 45 [0x7fff658daf6d]
        + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
        + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 1 (192 bytes) _libxpc_initializer (in libxpc.dylib) + 988 [0x7fff658daa26]
        + ! 1 (192 bytes) _xpc_collect_images (in libxpc.dylib) + 65 [0x7fff658db5e0]
        + ! 1 (192 bytes) dyld::registerLoadCallback(void (*)(mach_header const*, char const*, bool)) (in dyld) + 265 [0x1113a58b9]
        + ! 1 (192 bytes) _xpc_dyld_image_callback (in libxpc.dylib) + 89 [0x7fff658db6bf]
        + ! 1 (192 bytes) xpc_dictionary_create (in libxpc.dylib) + 40 [0x7fff658db0b5]
        + ! 1 (192 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (192 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (192 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (192 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 2 (112 bytes) _libxpc_initializer (in libxpc.dylib) + 142 [0x7fff658da6d8]
        + ! 1 (64 bytes) xpc_array_create (in libxpc.dylib) + 71 [0x7fff658dac3f]
        + ! : 1 (64 bytes) _xpc_calloc (in libxpc.dylib) + 52 [0x7fff658dacb6]
        + ! : 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! : 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + ! 1 (48 bytes) xpc_array_create (in libxpc.dylib) + 46 [0x7fff658dac26]
        + ! 1 (48 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + ! 1 (48 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + ! 1 (48 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + ! 1 (48 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        + 3 (96 bytes) _libxpc_initializer (in libxpc.dylib) + 1139 [0x7fff658daabd]
        + ! 2 (80 bytes) setenv (in libsystem_c.dylib) + 94 [0x7fff657614d9]
        + ! : 1 (64 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 35 [0x7fff65760dfb]
        + ! : | 1 (64 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : | 1 (64 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! : 1 (16 bytes) _owned_ptr_alloc (in libsystem_c.dylib) + 17 [0x7fff65760de9]
        + ! : 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! : 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + ! 1 (16 bytes) setenv (in libsystem_c.dylib) + 140 [0x7fff65761507]
        + ! 1 (16 bytes) __setenv_locked (in libsystem_c.dylib) + 625 [0x7fff657610fe]
        + ! 1 (16 bytes) malloc (in libsystem_malloc.dylib) + 24 [0x7fff65860783]
        + ! 1 (16 bytes) malloc_zone_malloc (in libsystem_malloc.dylib) + 139 [0x7fff6586082b]
        + 1 (64 bytes) _libxpc_initializer (in libxpc.dylib) + 978 [0x7fff658daa1c]
        + 1 (64 bytes) _xpc_create_bootstrap_pipe (in libxpc.dylib) + 45 [0x7fff658dae82]
        + 1 (64 bytes) _xpc_pipe_create (in libxpc.dylib) + 64 [0x7fff658eecd8]
        + 1 (64 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        + 1 (64 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        + 1 (64 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        + 1 (64 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]
        1 (128 bytes) libSystem_initializer (in libSystem.B.dylib) + 131 [0x7fff62b299cf]
        1 (128 bytes) _libtrace_init (in libsystem_trace.dylib) + 250 [0x7fff658bda54]
        1 (128 bytes) _dispatch_lane_create_with_target (in libdispatch.dylib) + 373 [0x7fff65669b12]
        1 (128 bytes) _os_object_alloc_realized (in libdispatch.dylib) + 35 [0x7fff65664682]
        1 (128 bytes) class_createInstance (in libobjc.A.dylib) + 83 [0x7fff645d683e]
        1 (128 bytes) calloc (in libsystem_malloc.dylib) + 30 [0x7fff65862cba]
        1 (128 bytes) malloc_zone_calloc (in libsystem_malloc.dylib) + 139 [0x7fff65862d62]


        This output makes clear that the allocations are coming from various static initializers in libSystem.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 5 '18 at 7:47









        bdashbdash

        15.2k14079




        15.2k14079
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462682%2funexplainable-malloc-call-in-simple-test-program-malloc-project%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            To store a contact into the json file from server.js file using a class in NodeJS

            Marschland