Tuesday, 3 January 2012

Android Mobile Applications Can Experience Memory Leaks Issues

Android is the most happening platform that is available now and is used extensively by the offshore android development. There are a number of Android mobile applications that are built on this platform. But despite its immense popularity Android development is not devoid of issues. One of the main issues that are faced by the offshore Android development teams is memory-leaks. This is because the maximum heap for mobile applications is 16GB. If you come to think of it for a phone the memory space is really high. But then for offshore Android development team who wants to achieve more, this much space is not sufficient. The main advantage of android is multi taking and hence it can take a lot of applications in the memory space. The memory leaks happen mainly because the term context is used for a lot of operations within Android development.  But then the main use of this is to access or load resources for the Android applications.  The widgets are constructed with the help of this context parameter. Application and activity are the two types of contexts that are available. Normally the activity is passed.

protected void onCreate (Bundle state) {
  TextView label = new TextView(this);
  label.setText("Leaks are bad");

When there is a small leak also it is dangerous, as it will slowly lead to a complete leak within the Android mobile applications. So one has to be very careful while writing an application so that there is no memory leak.

In short one has to keep in mind the following things to avoid memory leaks issues.

  • For a context activity does not have reference that is long lived that is the reference of the activity should not have a life cycle that is more than the activity. In short it should have the same life cycle.
  • One can also use context activity instead of the context application to minimize the memory leaks.
  • It is better in an activity that one does not use the non static inner classes in case you are not in a position to control the lifecycle. Use the static inner class which will make a weak reference to the activity. Hence the best way is to use the static inner class that has a weak reference to outer class.
  • One has to keep on mind that the garbage collector that is there is not like insurance for the memory leaks.

Share it Please

Sandeep Patekar

MD @ Mobi People INC. Working For Clients for Various types of mobile application / software development. Working from last 10 years in web based software & Moile based application development industry.


Post a Comment

Copyright @ 2013 Mobi People. Designed by Templateism | Love for The Globe Press