Anshuman Chatterjee | Posted on | 2 min Read

Uncover Memory Leaks by Mobile Apps

 

Mobile apps can often crash for many reasons. Nothing is as excruciating as memory leaks. It starts with your app crashing often, or becoming slow or maybe making your entire phone slow down, taking longer time to load activities. Memory leaks are notoriously hard to detect, and thus can easily surprise you. Have we ever thought why most of the users uninstall the application after some use?

Which is why it is critical for Developers to understand the memory consumption by any mobile application. How do you detect memory leaks during Mobile Application Testing? And if so, how can you prevent them from hogging mobile resource consumption?

A little knack for Mobile Application Testing always comes handy.

 

mobile application testing
Figure 1: Image Credit- GadgetHacks

 

Want to test your Mobile App?

Join pCloudy Platform!

Memory is critical to device

 

Memory is one of the key resources of the mobile device.And memory leaks in Android is an important thing to be kept in mind. Java is a garbage collecting language, which removes the need for developers to dig deep to manage allocated memory. This reduces the chances of any segmentation fault crashing an app or any unfreed memory allocation from eating up space of the heap area, thus creating a safer code.

 

However, a garbage collector is never an insurance against memory leaks. There are other ways by which memory can be leaked within Java. This means that your android mobile application is still pretty prone to wasting unnecessary memory allocation and crashing with out-of-memory (OOM) errors.

 

Toptal
Figure 1: Image Credit- Toptal

 

Why are Memory Leaks Bad?

 

Cause: Memory leaks occur when some variable of the application still has references to some objects that are unnecessary, no longer in use or used to be with the app anymore, is bloating the allocated memory heap and the Garbage Collector is not being able to release that memory.

Effect: Android devices mostly run on phones with limited memory, so as a result of too many leaks, the app runs out of available memory. This triggers more frequent Garbage Collector events which paralyze the device (Stop-the-world GC events) by almost stopping the rendering of UI and processing of events. This leads to an Out of Memory Exception and translates to the user as the app being unresponsive.

 

Android App Testing

 

Testing for Memory Leaks

 

Memory Leaks are caused by the failure to not be able to de-allocate memory that is no longer in use, which is why they cannot be identified during black box testing. The best phase to find the memory leaks is when developers are developing the application, at a code level.

It’s best to check for memory leaks during unit testing. However, testers can follow these tips:

 

Release Unused Memory: Memory leaks can be present because of the bad design of the application and thus might consume lot of memory when the application is in use

 

Test on Multiple devices:The memory consumption by the application should be monitored while doing the system & functional testing. One shouldn’t rely on a single device testing as there are plethora of devices in the market.

 

Detecting Memory Leaks

There are quite a few techniques and tools devised by developers to pin point memory leaks. Android’s very own Android Studio has a powerful tool to monitor not only memory usage but also for network, GPU and CPU usage as well, called the Android Monitor.

Memory Monitor in this helps track memory usage, find de-allocated objects, identify memory leaks and helps get an overall sense of how your app allocates and frees memory. It’s done in three steps:

1. During and use and debugging of app, track the memory monitor. If the memory usage graph rises for your app and doesn’t fall even if put in background, it’s a memory leak.

2. Using the Allocation tracker, you can check the percentage of memory allocated to different types of variables in your app. This gives you a sense of how much memory is consumed by which object.

3. Create a Java Heap Option to create a heap dump that keeps a snapshot of the memory at any given point of time, thus providing the data consumption data.

Despite Android’s monitor to detect memory leaks, there are a few platforms from developers that help extract memory consumption data without so many steps for faster testing cycles.

pCloudy’s very own platform for example, generates the statistics for Memory consumption while doing the normal functional Mobile Application Testing on real mobile devices.It also generates other vital data such as CPU consumption, battery consumption & data consumption for testers and developers who reiterate several test cycles across multiple physical devices.

 

mobile application testing
Figure 1: Image Credit- Android Developers Studio

Want to test your Mobile App?

Join pCloudy Platform!

Android App Testing

 

If you are anything like me, you’d agree that the armor of present day mobile phone technology has a few chinks on it. Nothing is worse than applications draining the battery resources of your mobile device faster than you can fill it back up. The sunnier side of course, is that you can create teachable moments for your kids better by hiding their phone chargers and watch the colors drain from their faces.

Studies show that battery life is a top priority for smartphone buyers. In fact, just recently, an IDC survey showed that 56% of Android buyers, 49% of iPhone buyers and 53% of Windows Phone buyers said that battery life was a key reason when they bought their particular device.

It is rare to find mobile app testing tools that assure proper usage of resource by the mobile app as, included in the overall test plan and strategy.

It’s rather a tedious and long process for conventional mobile app testing methods and as such, Let us talk about how resource consumption as an app takes top priority, because nothing stops a user to uninstall their resource draining apps from their phone. Also we’ll talk about how developers and testers efficiently test mobile apps for Android applications.

 

Android App Testing

Figure 1: IDC Survey

 

Why battery testing is important:

 

Thousands of new mobile apps are being launched every day. And these apps have gone beyond just utilities, games and shopping apps, nowadays, apps need to be integrated into self-driving cars, digital assistants, wearable devices etc. Billions of users need to install apps that are not only compatible with their varying devices, but also provide quality experience of the app so that it doesn’t prompt the user to uninstall it and move to an alternate app.

When you get worried about potential battery abuse, its fair economics to identify the markers that can cause increased consumption of energy by the mobile application. Critical are the functionality, usability, performance and security to make sure that the app does what it was meant to do, seamlessly. The growing need for perfect enterprise and consumer apps and the continuous need to upgrade the application to match it with what the consumer exactly wants is a job that creates high pressure for developers and testers alike, who are responsible to delivering them.

We would get deep into the best practices and tactics that should be kept in mind while testing for battery drain in your mobile app in a later blog post. For now, let us look at how developers can test for battery consumption during Android App Testing.

 

How to test battery consumption for mobile apps:

 

So far there hasn’t come a good automation method to test app battery drain. So testing Real Mobile Devices meets many requirements for efficiency in the process. Let us check out a few parameters to test battery drainage due to mobile apps.

 

  • Battery test flow

    This will vary based on the functionalities of the applications. But overall the below approach or points should be considered while testing for battery consumption.

    • Check the status of the battery before the test begins
    • Enable the location services for the application if app supports
    • Start the data sync of the application if app supports
    • Start the streaming service of the application if app supports
    • Check if the application send/receive the data when in the background
    • Check if the application send analytics to its server
    • Observe the battery consumption while doing above supported features by your application.

This will give us an idea as what is the battery consumption by the application.

 

  • Testing as end user

It is very critical to test the environment needs of the app from a real user perspective. Environments like device types, operating system, background popular apps installed and running, network conditions (WiFi, 2G, 3G, 4G, Roaming) as well as diverse set of devices with different battery states, brings DevOps teams as close as they can come to end users.

 

  • Android App Testing across varying devices

Android is guilty of OS fragmentation due to its open approach to OEM vendors. Different devices have varying battery capacity and each loses its battery chemistry over time, negatively impacting performance and battery hours. This is why we must check the battery consumption for the mobile app on variety of mobile devices. The best practice is to use multiple devices from device labs/ device clouds.

 

Different tools available in the market.

 

Android’s built in Battery App

Your Android Mobile Phone has a ubiquitous battery testing resource, as it comes preinstalled on all Android mobile devices. Android’s native battery analyzer, for example, (Settings> Device> Battery) is built into Android’s OS and helps analyze each app and let you know which are the ones draining the most fuel.

 

Commercial Battery Saving Apps

There are a few commercial Android Battery Analyzers which are available for free in the market, like:

 

GSam Battery Monitor can reset testing cycles as you go, which means there is no need for draining and recharging the battery like in android’s native battery app, and monitor app power usage without having to wait to get an information reset.

 

Clean Master on another hand, lets you know through its notification feature as and when an app is causing the phone’s battery/CPU to drain, which gives instant information on any CPU overuse.

Android App testing

 

pCloudy platform for Testing Battery Drain

pCloudy platform allows comprehensive features for Android App Testing. Moreover, Using pCloudy’s platform, one can monitor the battery consumption by the application. additionally, the user can also monitor memory, CPU and data consumption by the application.

The user can do the complete functional app testing on the application by touching all the critical/non-critical paths in the application. The pCloudy platform provides the necessary data for the work flow.

 

Performance Metrics

 

Conclusion

Google has said that this year their focus is on the ‘vitals’ of mobile phones, battery being one of the critical four. It’s always best to use varying angles of attack to test your app’s battery usage. And the only way to do that right now is to cover as many mobile device variants in the market and test against them.

 

To check battery consumption during Android App Testing Click Here.

 

Get 180 Device Testing Minutes Free




App Testing

If recent past has been any indication, then it is a certainty there are growing expectations from Testers and Developers alike, to take quality head on, as a joint feature. More so in the Mobile App Testing projects where changes are required faster than ever.

 

As part of DevOps practices, it’s has become imperative for developers to run as many tests as possible with every code check-in. These tests could be automated functional, API or Unit Tests. Some of the popular tools to used by Developers to create their tests are Espresso, XCTest and Appium.

 

Following are some the Challenges faced by developers:

  • Developers need access of right set of devices across different versions to be able to run their tests.
  • Debugging capability on those devices so that they can fix issues quickly.
  • Access to a specific model of devices to debug production issues.

Try taking a look at a typical developer’s cubicle and you will see a series of mobile devices connected with several long USB cables running into computers. It does get frustrating to see others furiously plugging USB cables in and out of the mobile devices for App Testing on various devices.

 

Many of the organizations are shifting to device cloud to provide their teams access of right Mobile Devices. Device cloud are solving the need of test teams but provide limited debugging capabilities and hence not preferred by Developers.

 

To directly address need of Developers, pCloudy recently introduced DeviceTunnel, which fully allows developers to take complete control of the device in cloud. This unique solution provides access of cloud devices through the Android Studio or Eclipse IDE and the command line tool installed in your computer.

 

It works as if Device is connected directly to your computer through a USB cable. From the point of view of tools like Android Studio or Eclipse, a cloud-based device appears physically attached. In reality, the Device Tunnel communicates with pCloudy’s servers over Internet.

 

App Testing

Access devices directly from your terminal

 

Once a connection is established, the developers can perform the following actions on these devices:

  • Issuing a range of ADB commands for debugging, shell creations, port forwarding, and viewing general information about any cloud-based Android device
  • Copying and pushing files to connected cloud-based devices
  • Installing and uninstalling applications
  • Debugging apps during development or testing by adding breakpoints, inspecting variables, analyzing run-time metrics to optimize your app and more
  • Run their tests on the device directly from their IDE

To know more on how to connect any device on pCloudy using Device Tunnel Click Here.

It is undeniable that developers and testers need quicker access to diverse devices for the brisk evaluation of app and debugging. Device Tunnel enables both sets of engineers to instantly connect to any device hosted on cloud and run faster debug sessions and thereby, maximize the quality of their build cycles.

pCloudy 4.3

 

  • User can directly send input to the pCloudy Android devices by using their system keyboard.
  • CPU and Memory graphs on iOS.
  • New Improved Automator Page.
  • Automator now works on devices for all region
  • Live view for the Automation run for devices from all region
  • Bug Fix: Remaining Credits now revert back after an Appium session finishes earlier than booking expiration time.

Click Here to check our Previous Release.