In the More C Concepts (Google webcache, not on Internet Archive), I read the following:
When the app is exiting or when the buffer is no longer needed, the memory must be freed for applications to use:
// Free dynamically allocated memory free(s_buffer);
In the Learning C for the Pebble SDK (Internet Archive), I read:
Unlike other languages (such as Python or JavaScript), the C language relies on the developers to manage any memory they use. This means that any memory allocated by a program for storing data must be freed up again by the developer so that other progams can make use of it.
I am used to programming on non-embedded scenarios where each application has its own address space and upon process termination the OS reclaims the memory allocated. However, the two above statements from Pebble’s SDK suggest that if I call malloc()
and then the program exits or is killed before calling free()
the watch will be unable to reclaim the memory. It also shows examples of deinitializing windows after the event loops exits, etc.
I was really hoping that if I needed to dynamically calculate a buffer size once at startup I could just not worry about cleaning it up before process exit. Of course, for things which have a shorter-than-process lifetime, I would need to track those and clean things up to avoid leaking and causing my app to run out of memory. But trying to do this for everything—and, more so, in a way that ensures that free()
or *_deinit()
gets called even when the program terminates uncleanly—seems both a waste of time and impossible.
How can one write a Pebble Watch app safely so that when the app is killed all allocated memory is deallocated? Or does Pebble’s OS track and clean up resources allocated by an app when it terminates like modern OSes?
The answer seems to be:
As you've seen, the official documentation is almost entirely silent on the subject, so short of a statement by a Pebble dev we won't be able to get a definitive answer. We have a few options to come close, though: the first is to turn to the Pebble forums:
We can also check that most reliable source, Reddit's /r/pebbledevelopers, who claim:
We may also look at this set of slides, particularly:
(I believe this only applies to Aplite, a.k.a. Pebble 1.O)
which would suggest that there's not much app "headroom" -- if an app or apps started leaking and weren't fully cleaned up by the OS, it would quickly make it impossible to launch new apps.
In conclusion: I wouldn't worry too much about it.