Reputation: 79
Is there a programmatic way to free up an iPhone's memory that is as effective as rebooting an iPhone?
Thanks a lot.
Upvotes: 0
Views: 775
Reputation: 4198
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.
Upvotes: 1
Reputation: 9453
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.
Upvotes: 0
Reputation: 20236
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.
Upvotes: 6