Monday, March 7, 2011

My Video Interview at Mobile World Congress 2011 @ Barcenola

Memory Management (m-Cube Level 1)

Memory is one of the main resources for mobile devices. Managing this resource in an optimum manner is one of the main challenges for mobile application developers… Even though there are numerous devices in the market today that have good memory capacity… it is still important that the memory management is not neglected.
While developing mobile applications, one should always use optimal solution for memory usage. For instance, if applications want to display an image on the screen, then using PNG format instead of BMP is advised..

If a single application is used for multiple screen resolution devices, then all the resources should be downloaded from the server at the first launch. This way… the application need not increase its size by packing all resources of different screen sizes together in the final distributable.

If the application want to display a tile pattern in the background of the screen.. it will make more sense to use a small image and render it multiple times on the screen to create the impression of a big image. This way, the applications can reduce the actual memory required to store that big image and it will help in scalability of the app to other screen resolutions.

Also … applications should consider memory fragmentation rules as to allocate memory in the power of 2.
let’s suppose it would require 15 bytes to store a string, applications should allocate 16 bytes (2^4) as it would be easier to add/delete those memory blocks.
Also, try to allocate large chunks rather than small ones. For example, instead of allocating a single object, allocate an array of objects at once and then start the processing the same.
Another factor is Lazy loading, also known as dynamic function loading. Here, applications do not load all the components by default into the memory when a program is started…
In lazy loading, all dependent components will be loaded as and when required by the application. It can be used to improve the performance of an application, if most of the dependent components are not used together on a single screen but are required at different points in the application flow.

All mobile applications should ensure that they do not use more memory than actually necessary.
Memory management should also adhere to the guidelines of the corresponding OS. For example, an iPhone app should follow the guidelines for using an AUTORELEASE POOL.
If the applications want to store a received object completely in an instance variable, then they must retain or copy it. They should generally not use weak references and decide where they would require a Deep Copy of objects and where a shallow copy will do.