Adobe 29400084 User Guide - Page 28

Managing Flash Lite file memory for mobile devices

Page 28 highlights

DEVICE CENTRAL 25 User Guide • Limit the use of global variables, because they are not marked for garbage collection if the movie clip that defined them is removed. • Avoid using the standard user interface components (available in the Components panel in Flash). These components are designed to run on desktop computers and are not optimized to run on mobile devices. • Whenever possible, avoid deeply nested functions. • Avoid referencing nonexistent variables, objects, or functions. Compared to the desktop version of Flash Player, Flash Lite 2 looks up references to nonexistent variables slowly, which can significantly affect performance. • Avoid defining functions using anonymous syntax. For example, myObj.eventName = function{ ...}. Explicitly defined functions are more efficient, such as function myFunc { ...}; my Obj.eventName = myFunc;. • Minimize the use of Math functions and floating-point numbers. Calculating these values slows performance. If you must use the Math routines, consider precalculating the values and storing them in an array of variables. Retrieving the values from a data table is much faster than having Flash calculate them at run time. For more tips and techniques for creating content for mobile phones and devices, see www.adobe.com/go/learn_cs_mobilewiki_en. Managing Flash Lite file memory for mobile devices Flash Lite regularly clears from memory any objects and variables that a file no longer references. This is known as garbage collection. Flash Lite runs its garbage-collection process once every 60 seconds, or whenever usage of file memory increases suddenly by 20% or more. Although you cannot control how and when Flash Lite performs garbage collection, you can still free unneeded memory deliberately. For timeline or global variables, use the delete statement to free the memory that ActionScript objects use. For local variables-for example, a variable defined within a function definition-you can't use the delete statement to free an object's memory, but you can set to null the variable that references the object. This frees the memory that the object uses, provided there are no other references to that object. The following two code examples show how to free memory that objects use by deleting the variable that references those objects. The examples are identical, except that the first example creates a timeline variable and the second creates a global variable.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

DEVICE CENTRAL
User Guide
25
Limit the use of global variables, because they are not marked for garbage collection if the movie clip that defined
them is removed.
Avoid using the standard user interface components (available in the Components panel in Flash). These compo-
nents are designed to run on desktop computers and are not optimized to run on mobile devices.
Whenever possible, avoid deeply nested functions.
Avoid referencing nonexistent variables, objects, or functions. Compared to the desktop version of Flash Player,
Flash Lite 2 looks up references to nonexistent variables slowly, which can significantly affect performance.
Avoid defining functions using anonymous syntax. For example,
myObj.eventName = function{ ...}
.
Explicitly defined functions are more efficient, such as
function myFunc { ...}; my Obj.eventName =
myFunc;
.
Minimize the use of Math functions and floating-point numbers. Calculating these values slows performance. If
you must use the Math routines, consider precalculating the values and storing them in an array of variables.
Retrieving the values from a data table is much faster than having Flash calculate them at run time.
For more tips and techniques for creating content for mobile phones and devices, see
www.adobe.com/go/learn_cs_mobilewiki_en
.
Managing Flash Lite file memory for mobile devices
Flash Lite regularly clears from memory any objects and variables that a file no longer references. This is known as
garbage collection. Flash Lite runs its garbage-collection process once every 60 seconds, or whenever usage of file
memory increases suddenly by 20% or more.
Although you cannot control how and when Flash Lite performs garbage collection, you can still free unneeded
memory deliberately. For timeline or global variables, use the
delete
statement to free the memory that Action-
Script objects use. For local variables—for example, a variable defined within a function definition—you can’t use
the
delete
statement to free an object’s memory, but you can set to
null
the variable that references the object. This
frees the memory that the object uses, provided there are no other references to that object.
The following two code examples show how to free memory that objects use by deleting the variable that references
those objects. The examples are identical, except that the first example creates a timeline variable and the second
creates a global variable.