When I create an 8MB NSMutableData
object my memory usage does not seem to change. Is it normal?
My code is as following:
NSMutableData *myData;
myData = [[NSMutableData alloc] initWithLength:(8*1024*1024)]; // init with 8 MB
When I debug step by step, the memory usage stays at 5.8 MB, even after the object has been allocated... It should go up to 13.8, shouldn't it? I am using ARC (but with MRR it is the same...).
If I try to access the data, memory usage remains the same:
uint8_t *fBuffer;
fBuffer = (uint8_t *)malloc(8*1024*1024);
[myData getBytes:fBuffer length:8*1024*1024];
In fact, if I modify the data, then the memory usage goes up as it should!
for (int i= 0 ; i<8000000 ; i++) {
fBuffer[i] = 0x32;
}
=> memory usage is now 13.4 MB.
Thank you all for your help, I now understand how it is supposed to work.