Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development Knowledge Base

Memory limits of a Headless app

by Retired on ‎03-21-2014 04:05 PM (1,632 Views)

Headless Applications are limited by a preset amount of memory (E.g. 3MB) to keep its impact on the system at a minimum. The system does not kill applications that cross this limit but instead it blocks further allocation of heap memory. Depending on how you handle allocation errors, your application may or may not crash. It is also important to note that this limit only applies to the heap of the headless portion and does not apply to the UI portion.


It is therefore a good practice to track the heap usage in real time within your headless project. The following code snippet can be reused in any application to do just that.  


#include <sys/procfs.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdint.h>
int64_t App::measureMem() { int rc, n, i, num; int64_t memsize = -1ll; procfs_mapinfo *maps = NULL; int fd = open("/proc/self/as", O_RDONLY); if (fd == -1) return -1ll; do { rc = devctl(fd, DCMD_PROC_PAGEDATA, NULL, 0, &num); if (rc) goto cleanup; maps = (procfs_mapinfo*) realloc(maps, num * sizeof(*maps)); if (!maps) goto cleanup; // pre-subtract the allocation we just made, rounded up to page size memsize = 0ll - ((num * sizeof(*maps) + __PAGESIZE - 1) & ~(__PAGESIZE - 1)); rc = devctl(fd, DCMD_PROC_PAGEDATA, maps, num * sizeof(*maps), &n); if (rc) { memsize = -1ll; goto cleanup; } } while (n > num); for (i = 0; i < n; i++) { if ((maps[i].flags & (MAP_ANON | MAP_STACK | MAP_ELF | MAP_TYPE)) == (MAP_ANON | MAP_PRIVATE)) { memsize += maps[i].size; } } cleanup: close(fd); free(maps); return memsize; }


While it is expected that headless applications are extremely optimized to stay within the heap limit set on them, it is also well recognized that some applications or application features simply need a bigger chunk of the heap. If that is the case, please reach out to headlessdevsupport -at- blackberry ~dot~ com with your use case. 

Users Online
Currently online: 36 members 1,624 guests
Please welcome our newest community members: