Search code examples
iosobjective-cnsdata

Release NSData not release all memory


I'm using this code to get NSData of a specific file:

NSData* data = [[NSData alloc] initWithContentsOfURL:object.fileURL];

Before this line the memory usage was 18MB and after this line it become 66.1. right after i want release this object(Non-ARC class) so i call [data release]; And the data memory usage becomes 43 instead of 18MB.

Any idea what can be the problem? how i. can fix it?


Solution

  • This is likely not an actual problem. Apps do not always return all memory since they may need it again. The OS may later require the memory back, but in the meantime it is much more efficient to let apps keep allocated memory if there is no pressure.

    If you continue to allocate and release memory, does the app's memory footprint continue to grow, or does it stabilize at 43MB? If it continues to grow, then you do have a memory leak, and can debug that using various tools. If it has a one-time jump, then that is intentional.