Wednesday, September 2, 2009

Why Are iPhone Application Developers Doing This?

iPhone application developers have been adding functionality that allow users to "free memory" on demand.  Unfortunately, Apple has begun telling these developers to remove this functionality from their iPhone applications (Apple Forces Removal of 'Free Memory' Functionality From iPhone Applications).  This has forced companies like Recession Apps, to remove their app from sale.

I talked to an iPhone app developer about this and asked him why this sort of functionality is needed.  He told me that memory management for the iPhone, or lack thereof, is woefully inadequate in some situations.  He did say that Apple provides plenty of information as to what can happen under low memory conditions and what to do about it.  And there are numerous examples provided, as well as advice (from real Apple engineers) given in the developer forums.  The problem is that the guidance given does not work in all situations, especially in very critical memory situations. 

It's up to the programmer to allocate and de-allocate memory blocks. When other apps, such as Safari, iPod, and Mail, unexpectedly gooble up needed memory, a warning is sent out. The programmer has an opportunity upon receiving this warning to do something about it, like throwing objects overboard to free up memory.  At the same time,  the iPhone OS will ask apps like Safari to start closing its pages and giving back memory.  Unfortunately this does not work well, particularly when memory goes critical after an app has passed control to an api, such as the camera. In those cases, the app doesn't get the warning in time.  Moreover, Safari is slow at giving back memory, and by the time it does close enough pages, an app either slows way down or crashes.  In other words, there are situations where it's impossible to do the recommended memory house keeping, and this invariably leads to a crash.

With the introduction of the iPhone 3GS, this is not as big a problem because there is more primary memory space provided to all apps, but remains a problem with the first two generation of iPhones.  And that's why the "free memory" apps have been so popular - they provided a way to "blow the carbon out of the cylinders" and release more memory for apps.  The programmer I spoke to showed me just how low memory can get.  He opened up several Safari windows and then used another tool to calculate low memory.  Memory got as low as 1.5MB in some instances.  But by running a "free memory" app, the amount of free memory went from 1.5MB to over 40MB.  Big difference, but I suppose it's at the expense of Safari and Mail, since Apple is warning developers about it.

The bottomline for iPhone application testers - ensure you test for low memory conditions to make sure the app under test handles the situation gracefully and without crashing.

3 comments:

Amit Modi said...

This is surely an excellent and well thought out post. But Remember that a manufacturer will do what it thinks is in the best "business interest" of it. -amit Rapidsoft Systems, IN. www.rapidsoftsystems.com

Ray Vizzone said...

Amit, I agree with you and certainly we've seen Apple act in their own best interest.

-Ray

kona said...

Balliro Commerce Group offers premier design and development services, app developer

Post a Comment