Monday 24 June 2013

Garbage Collector - Titanium Module for Android


Recently I developed an native module called Garbage Collector Module and published in Appcelerator Marketplace.


This module is used to Monitor your android device heap memory and force the garbage collector for free the unused objects.

Using this module we can get following informations,
  • MaxVMHeapSize
  • NativeHeapSize
  • VMHeapSize
  • TotalHeapSize
  • VMAllocatedHeapSize
  • NativeHeapAllocatedSize
  • VMHeapTotalAllocatedSize
  •  VMHeapFreeMemory
  • VMHeapTotalFreeMemory
And Also we have two more public methods called,
  • isOutOfMemoryException()   - we can check the Memory exception before app get crash.
  • callGC() - This method force the garbage collector and release the memory occupied by unused objects.
 Accessing the Garbage Collector Module

To access this module from JavaScript, you would do the following:

var garbagecollector = require("prakash.garbagecollector");

Force Garbage Collector

garbagecollector.callGC(); 

Check MemoryException

garbagecollector.isOutOfMemoryException();  returns true/false

Check Heap Memory Status
garbagecollector.getMaxVMHeapSize();
garbagecollector.getNativeHeapSize();
garbagecollector.getVMHeapSize();
garbagecollector.getTotalHeapSize();
garbagecollector.getVMAllocatedHeapSize();
garbagecollector.getNativeHeapAllocatedSize();
garbagecollector.getVMHeapTotalAllocatedSize();
garbagecollector.getVMHeapFreeMemory();
garbagecollector.getVMHeapTotalFreeMemory(); 

Sample App Screenshot
Module URL :

https://marketplace.appcelerator.com/apps/5834?2036618235