Acknowledged

CIQ background docs do not state that global variables are always included in the background

https://developer.garmin.com/connect-iq/core-topics/backgrounding/

The documentation says:

The Connect IQ compiler allows you to select what code is necessary for running in the background with the :background annotation. Only modules, classes, functions and member variables decorated with the :background annotation will be compiled into your background service. This means you must decorate all related code with the annotation (including your Application class).

But according to the following thread, global variables are always included in the background process:

https://forums.garmin.com/developer/connect-iq/f/discussion/388992/background-memory-error--403/1850430#1850430

Also, the docs don't mention a couple of edge cases:

1) If the :background annotation is not used at all, the entire application is loaded into the background, with a compiler warning

e.g. "The 'Background' permission was enabled but no source code was annotated. The entire application will be loaded as a background process."

2) If the :background annotation is used, but not on the app entry point / AppBase-derived class, the entry point is implicitly added to the background process, with a warning

e.g. "The entry point '$.SimpleDataFieldApp' was implicitly added to the background process since the app contains declarations annotated with (:background)."

  • This is a nice observation and information I didn't know.  I hope the optimizer is still able to remove unused globals from the background.

  • If global variables (and any other items, such member variables of the app entry point class) are always implicitly included in background processes, it might also be nice if there was a compiler warning to this effect. (I can see how this could be a problem for devs who want to eliminate all warnings, though. To eliminate the warning, they would presumably be forced to explicitly annotate all implicitly included symbols with :background, but that actually might not be a bad thing.)