Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Memory Module

The Memory Module is used to to retrieve the current available memory or notification of memory dropping below a user defined value.

Syntax

memory (Module) <META> Syntax

<META HTTP-Equiv="Memory" content="[method / parameter]">

<META HTTP-Equiv="Memory" content="memoryEvent:url('[jsFunction | url]')">

Memory JavaScript Object Syntax:
By default the JavaScript Object 'memory' will exist on the current page and can be used to interact directly with the memory.
To Invoke memory methods via JavaScript use the following syntax: memory.method();

e.g. memory.getMemoryStats();
To Set memory parameters via JavaScript use the following syntax: memory.parameter = 'value'; remembering to enclose your value in quotes where appropriate.

e.g. memory.lowMemThreshold = 'value';
To Set memory return events via JavaScript use the following syntax: memory.event = JavaScript Function;

e.g. memory.memoryEvent = 'doFunction(%json)';

For more details on the event syntax and parameters see the Retrieval Events page.
To set multiple EMML parameters / events on a single line use the following syntax: memory.setEMML("[Your EMML Tags]");

e.g. memory.setEMML("lowMemThreshold:value;memoryEvent:url('JavaScript:doFunction(%json)');getMemoryStats");
Memory Ruby Object Syntax:
By default the Ruby Object 'Memory' will exist on the current page and can be used to interact directly with the Memory. All Methods, Parameters and Events are the same as JavaScript, however, notice 'Memory' needs to start with an uppercase letter. Another difference in Ruby is that methods do not end in '()'
To Invoke Memory methods via Ruby use the following syntax: Memory.method()

e.g. Memory.getMemoryStats
To Set Memory parameters via Ruby use the following syntax: Memory.parameter = 'value' remembering to enclose your value in quotes where appropriate.

e.g. Memory.lowMemThreshold = 'value'
To Set Memory return events via Ruby use the following syntax: Memory.event = url_for(:action => :event_callback)

e.g. Memory.memoryEvent = url_for(:action => :memory_event_callback)

For more details on the event syntax and parameters see the Retrieval Events page.

To access the event parameters in a Ruby callback function, you reference the @params object within the callback function. This object is simply a ruby hash {"parameter1 name" => "parameter1 value", "parameter2 name" => "parameter2 value", ...}

Methods

Items listed in this section indicate methods or, in some cases, indicate parameters which will be retrieved.

Name Description Default Value
getMemoryStats This returns the current status of the device such as total memory and available memory via memoryEvent N/A

Parameters

Items listed in this section indicate parameters, or attributes which can be set.

Name Possible Values Description Default Value
lowMemThreshold:[Value] Values in KB The minimum amount of available memory, specified in KB. 10% of the total memory

Events

Values are returned to the caller in RhoElements via Events. Most modules contain events and those returned from this module are given below along with the event parameters. Events can cause a navigation to a new URL or a JavaScript function on the page to be invoked. Each event will in most cases have a number of parameters associated with it which will either be strings or JavaScript arrays. Event parameters can be accessed either directly or via JSON objects.


memoryEvent

The memoryEvent event is triggered when the available Memory drops below the set value.

ID Name Description
1 totalMemory The total memory in the device, specified in KB
2 availMemory The available memory in the device, specified in KB

Requirements

RhoElements Version 2.1 or above
Supported Devices All supported devices except Enterprise Tablet.
Minimum Requirements None.
Persistence Non Persistent - Changes to this module will not persist when navigating to a new page.

HTML/JavaScript Examples

The following example sets the lowMemThreshold to 1500 KB:

<META HTTP-EQUIV="Memory" CONTENT="lowMemThreshold:1500; memoryEvent:url('JavaScript:notification('%s');');">

The following example sets the memory threshold value to 10% of the total memory in the device:

<HTML>
    <HEAD>
    <TITLE>memory Notification</TITLE>
    <META HTTP-EQUIV="memory" content="memoryEvent:url('javascript:getMemory(%json);')">            
    </HEAD> 
    <SCRIPT type="text/javascript">
    function getMemory(jsonObject)
    {
        alert("Total Memory: " + jsonObject.totalMemory + "KB, Avail Memory: " + jsonObject.availMemory + "KB");        
        memory.lowMemThreshold  = jsonObject.totalMemory / 10;
        memory.memoryEvent = "onLowMemory(%json);";     
    }   
    function onLowMemory(jsonObject)
    {
        alert("The device is running low on memory, only " + jsonObject.availMemory + "KB is left on the device");          
    }   
    </SCRIPT>
    <BR><BR><INPUT type="button" value="GetMemory" onclick="memory.getMemoryStats();">
</HTML>
Back to Top