简体   繁体   中英

IPhone - free up memory

Is there a programmatic way to free up an iPhone's memory that is as effective as rebooting an iPhone?

Thanks a lot.

No. iOS is based on Mac OS X, and uses an overcommitting VM. It will release memory as it's required. Free your own things you malloc, release ownership of objects you control, implement didReceiveMemoryWarning to act sanely for your data sets, and you should be fine. Backgrounded apps will be killed if there's not enough memory before iOS kills you.

Short answer is NO. And agree with jer above.

There used to be an App which used to free memory in iPhone by allocating all free memory except 2MB on the device and then releasing it, causing the device to raise memory warning and free memory. However, there is no way you can free memory as effective as rebooting the iPhone.

If you allocated your memory with init, new or copy , you have 3 options.

A) You can explicitly and immediately free the memory through a call to release function.

B) You can tell iOS to release it "whenever it wants" by creating your objects with a call to autorelease method.

C) You can create your own autorelease pool to gain the control of releasing the autoreleased objects like so:

NSAutoreleasePool *rPool = [[NSAutoreleasePool alloc] init];
        MyObject *obj = [[[MyObject alloc] init] autorelease];
[rPool drain];

Hope that answers your questions about memory releasing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM