Memory footprints are the signs and ways of using memory during runtime. From the point of game memory usage optimization, monitoring the memory footprint is very important:
Using log messages has been the most effective and immediate debugging technique. Message logs are very useful for tracking the program control flow and runtime object tracking.
The Dalvik message log is useful for tracking memory. Whenever garbage collection happens, the garbage collector can print the following information through Dalvik log messaging:
GC_CONCURRENT
, GC_FOR_MALLOC
, GC_HPROF_DUMP_HEAP
, GC_EXPLICIT
, or GC_EXTERNAL_ALLOC
.The ART message log is also capable of showing or tracking memory footprints. However, it is not triggered unless explicitly requested.
If the garbage collector pause time exceeds 5 ms or the garbage collector takes more than 100 ms to execute, then garbage collector logs are printed. In the case of ART, the following information can be shown as logs:
Concurrent
, Alloc
, Explicit
, NativeAlloc
, CollectorTransition
, HomogeneousSpaceCompact
, DisableMovingGc
, or HeapTrim
as the reason for collection.The developer can check the heap usage per update. It gives a clear picture of the memory footprint. Heaps can be monitored with the help of several tools. There are plenty of device memory monitors available in the market. DDMS device monitor is one of them. It is a powerful tool that observes heap usage during the game's runtime.
The Android SDK comes with an inbuilt device monitor at <sdk>/tools/monitor
.
The memory monitor in Android Studio is useful for Android Studio users. Monitors can interact with the Android application to watch heap update with each garbage collection. Through this, the Android developer can know about exact memory usage for each segment of an application.
Sometimes, developers switch on/off methods to check exact heap usage. Thus, it becomes easier to optimize it further.
This is helpful for memory optimization. Memory allocation can be monitored through an allocation tracker.
Memory allocation tracking is required after a certain stage of memory optimization. This helps identify each and every object's memory allocation. Often, many useless objects stay back in memory. The developer can identify these objects and remove them for greater memory optimization.
Memory allocation tracker is available with both Device Monitor in Android SDK and Allocation Tracker in Android Studio.
However, it's not necessary to remove all allocations from performance-critical code paths; yet, the allocation tracker can help developers identify important issues in code. For instance, some apps might create a new Paint
object on every draw. Moving this object into a global member is a simple fix that helps improve performance:
Let's have a quick look at the allocation information obtained:
In game development, the number of objects in memory is immense, so it is very difficult to keep track of allocation and deallocation of objects manually. This monitoring tool helps find out the hidden spots that could have been easily ignored during the optimization process.
Overall memory usage of an Android game is distributed in different segments in RAM. This creates a general idea about application performance and memory security.
Basically, there are two types of allocation.
This is the dedicated memory portion used by the game during runtime. The Android operating system allocates this memory to the application. Private RAM is distributed in two segments:
Private dirty RAM is the most expensive one as it can only be used by specific applications (in our case, it is an Android game).
This segment of RAM is used by multiple processes. It is basically shared memory. Any RAM pages that are unique to the application process directly contribute to its PSS, while pages that are shared with other processes contribute to the PSS value only in proportion to the amount of sharing.
Memory leakage is a serious threat to software development. So, it is absolute necessary to track memory leakage and resolve it. When a process allocates memory and loses the reference pointer, then it is impossible to free the memory within the process.
There are few debug tools that can do this job to track down memory leakage. However, there is another free and more effective solution. The developer can always monitor memory consumption at any given point of time. A game runs within an update loop. So, it is possible to track the memory peaks of different game cycles. If the peak keeps increasing, it means there are leaks in the allocation/deallocation of memory. Now, the developer can check the size of each object and hunt down the leakage. Another benefit of this process is finding unnecessary objects in memory alongside memory leakage.
18.188.190.175