Software Testing Blog

Dude, where is my battery?

My unbounded desire to try new Apps on my phone finally met its match as I ran out of space on my phone’s storage device. So I figured I should use the opportunity and do some cleanup. One feature I like on the phone is that it gives me an idea of my usage pattern. Here are the top 5 Apps on my phone in terms of usage:

1. Task Killer
2. Email client
3. Facebook client
4. RSS Feed Reader
5. Calendar

The Task Killer is understandably the most frequently used App. It does something similar to ‘pkill’ on Linux systems and kills Apps and tasks running in the background. I care about how long my cell phone battery lasts on a single charge. Apps that run as background tasks have to be very careful about how they use resources from the underlying operating system. Any unnecessary or unexpected use of resources directly affects battery life.

My phone runs Java Apps. Java offers the benefit of a garbage collector that cleans up memory resources from data objects that cannot be accessed in the future. However there are limitations on relying on the garbage collector. The garbage collector does not reclaim memory promptly. The objects have to go out of scope and enough memory has to be allocated to trigger the garbage collection.

Another key limitation of the garbage collector is dealing with leaking system resources other than memory such as file handles, sockets and database statements or connections.

As always, let’s look at an example:

try {
stmt = dbCon.createStatement();
queryResults = stmt.executeQuery(…);
// do stuff with queryResults
} catch (SQLException e)  { //error
// Oops: forgot to close stmt.

In the catch block, we missed closing ‘stmt’. A leaking database statement like this or other resources like a media player objects in background tasks can drain the battery very quickly. In some cases, ‘lock’ resources can be brutal on the battery if acquired and not released.

As a user, I am willing to sacrifice features and capabilities from an App as I place more importance on basic functionality such as battery life. But I should not have to make that sacrifice if the Apps have addressed underlying defects that can compromise the basic functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *