jeudi 5 mars 2015

iOS:memory allocated using "malloc" auto released?

I'd like to reproduce a crash bug of my app under memory pressure, so I want to alloc much memory when my app launch and expect it under memory pressure. I use the code below:



void *p[300];
NSInteger allocatedMB = 0;

for (int i = 0; i < 300; i++) {
p[allocatedMB] = malloc(1024 * 1024);
memset(p[allocatedMB], 0, 1024 * 1024);
allocatedMB += 1;
}


I expect to alloc 300M memory, and never free it. but I always get this result on my iPhone:


enter image description here


It alloc only 150M and later free it to only 71M. But it appear as I expect when in simulator:


enter image description here


I'm not quite clear about this, any answer will be appreciated about why and how I can do this on my iPhone!




Aucun commentaire:

Enregistrer un commentaire