Manage Memory Heap on Mobile

Sannyasin Brahmanathaswami brahma at hindu.org
Sun Jul 17 23:15:48 EDT 2016


Do we have any discussion anywhere on the memory heap occupied by LC objects as they correlated to the different spaces discussed here?

https://developer.android.com/training/articles/memory.html

??

"In order for the garbage collector to reclaim memory from your app, you need to avoid introducing memory leaks (usually caused by holding onto object references in global members) and release any Reference objects at the appropriate time (as defined by lifecycle callbacks discussed further below). For most apps, the Dalvik garbage collector takes care of the rest: the system reclaims your memory allocations when the corresponding objects leave the scope of your app's active threads."

I guess the question, in LC terms, becomes, what is retained "holding onto" and what is "released" as you display cards, images, instantiate "big data" into custom props/arrays, read text files into globals etc.

My particular use case is this:

The "quotes" table in our database has 20,500 records. Exported form MySQL as JSON, we get a 9.5 MB file.

I prefer my "human readable" text format which uses a (cr & |) at the end of each record… and tabs in between columns

| quote_id [tab] subject [tab] citation [tab] content [tab] source_item_id [tab] source_url [tab] author [tab]author_dates

This is very lean, allows for line breaks inside the content column. and I can open and edit in any text editor with each record beginning on a new line.
This format is a 7.2MB file, and easily to split into an LC array.  

split aAllQuotes with "|" & tab

You just have to remember there is trailing CR at the end of each of the last column (in this case "author_dates") which is rarely an issue.

In our previous "Gurudeva.app" we has a similar file, but it was only about 700k… we read it into memory on start up, parsed this into an array and kept it in a global for instant access.

But I suspect keeping an 8MB global is bad thing on mobile… when we say "not much memory/RAM" what exactly are we talking about?  I suppose the more apps the user has open, the smaller the heap for any one of them…? 

Insights on best way to go if you wanted to get a random quote from the 8 MB file? 

typically we don't really want a random quote from all 20,000+ records, but a random quote from a subset of those… so perhaps breaking it into smaller files is a better way to go.. but eventually the app will read each one of those… so are they do they stay in memory?  with CPU speeds perhaps the I/O time to read from disk, get what you want and then "release" the space (how would you do that?) is the better way to go… 

Insights?


BR








More information about the use-livecode mailing list