background image
C H A P T E R 1 7
Additional System Services
Using Additional System Services
17-13
The following code example removes all alarms an application has scheduled for
the next five minutes:
foreach alarmKey in GetAppAlarmKeys(":MyApp:MySig") do
if not (GetAlarm(alarmKey).time > Time() + 5) then
RemoveAlarm (alarmKey);
Removing Installed Alarms
17
The functions
RemoveAlarm
and
RemoveAppAlarms
remove a particular alarm
and all of an application's alarms, respectively. The
RemoveAlarm
function takes
the alarm key of the alarm to remove as its single argument. Use of this function is
demonstrated in the code example in "Retrieving Alarm Keys" beginning on
page 17-12.
The
RemoveAppAlarms
function takes an alarm key suffix as an argument and
removes all alarms whose key ends with this suffix. For this reason it is important
for all alarms created by a particular application to use alarm keys ending with the
same suffix. If your application's alarm are not meaningful if your application is
not installed, you should call this function in your application's
RemoveScript
function.
Common Problems With Alarms
17
This section describes common problems encountered with use of the alarm service.
Problems With Alarm Callback Functions
17
Alarms are kept in a soup; thus, they persist across restarts and installation or
removal of packages. This means that the arguments you pass to your callback
function are also stored in a soup; hence, these arguments are also copied deeply.
(See the description of the
DeepClone
function in Newton Programmer's
Reference.) Therefore, you must avoid indirectly referencing large objects lest
they unnecessarily inflate the size of your entries in the alarm soup.
A classic example of accidentally referencing a large object is in dynamically
creating the function object executed with the alarm. Function objects may contain
references to the lexical environment and the current receiver (
self
) at the time
they are created. For example, function objects created from a view method reference
the root view through their parent chain. If you pass such a function object to the
AddAlarm
function, the system attempts to copy the entire root view into the
alarm soup. One way to minimize the size of your callback function object is to
pass as your callback a one-line function that invokes a method in your application
package to actually do the work.
© 2007-2017, o7 studio » при воспроизведении материала сайта ссылка обязательна