Reputation: 26972
I have an app that struggles to perform well on iOS 5 running on an iPad 1. It's crashing with LowMemory warning very regularly.
The app is huge, complicated (..convoluted), uses core data,....
I want to attempt to reduce the peak memory footprint. There are autoreleased objects everywhere that I could go around converting, but that could take me forever.
Will converting the project to ARC automatically convert those autoreleased objects to retain/release when it is compiled with ARC.....and possibly reduce my peak memory footprint?
Thanks
Upvotes: 1
Views: 268
Reputation: 92384
ARC does lower your peak memory footprint, but usually only marginally. The exception is if you're doing a lot of autoreleased work within the same runloop cycle or you have a thread where you only have one autorelease pool that you never drain.
Consider:
- (void)myBackgroundThread
{
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
for (int i = 0; i < 1000000; i++) {
NSString *dummy = [NSString stringWithFormat:@"%d", i];
NSLog(@"%@", dummy);
}
[pool release];
}
This will generate at least a million autoreleased string objects (NSLog might generate some more, I don't know). They all add up until the loop is finally done and the pool is released.
However, with ARC, it would look like this:
- (void)myBackgroundThread
{
for (int i = 0; i < 1000000; i++) {
NSString *dummy = [[NSString alloc] initWithFormat:@"%d", i];
NSLog(@"%@", dummy);
// The compiler inserts "objc_release(dummy);" here
}
}
So the temporaries get cleaned up immediately, lowering the peak.
Upvotes: 1
Reputation: 14694
ARC might help, and it might not. It depends on how well you are managing the memory without it. I would guess though, that there are other design decisions you made that should be reconsidered - fixing those would go much further towards accomplishing your goal.
Upvotes: 1
Reputation: 12405
hmm.. I think it will surely bring down your footprint but the effect won't be too dramatic. The memory footprints depends more upon the design of your code, the way you create your objects and how effectively you use the same object over and over again.. any other ideas anyone.. ?
Upvotes: 1