moonshadow
moonshadow

Reputation: 89115

releasing memory after vm_allocate

I would like to create a large, contiguous, partially resident address space region.

I am allocating a large region in my iOS app using vm_allocate. iOS automatically finds a suitably large contiguous unused address space region for me and hands me a pointer to that, which is nice.

iOS then automatically backs this with physical memory pages as I write to it, so my app's physical memory usage starts out small and grows as necessary over time. So far so good.

Occasionally I stop using parts of this memory region for a time. My app keeps track of which portions of this region are actually in use at a given time and which are not. However, I cannot seem to identify a way of passing this information to the OS, so I can never shrink my app's physical memory usage (e.g. in response to a low memory warning).

In other, less magical, environments, this codebase reserves a contiguous block of address space, then manually attaches and detaches physical pages as necessary.

Am I missing some vital bit of Apple documentation? - is there a comparable API I could be using instead of vm_allocate to achieve this; or, alternatively, is there a way I could place pages of vm_allocated address space back into their initial "uninitialised, automatically mapped on next write" state?

Upvotes: 3

Views: 1007

Answers (1)

abdul sathar
abdul sathar

Reputation: 2396

kern_return_t kr;
unsigned int nbytes = yourMemroySize;
unsigned int address  ; 

vm_deallocate(mach_task_self(),address, nbytes);

I have used this code for releasing memory it works fine.I know this is very very late answer ,i hope it will use some one..

Upvotes: 2

Related Questions