Summary
- Lazy-load bitmap resources instead of creating them at startup.
- This should apply broadly, not just to the battery charging or Bluetooth icons.
- The goal is to reduce baseline heap usage while keeping rendering behavior unchanged.
Rationale
- Current logs show the status bar eagerly loads multiple bitmaps up front.
- Static palette cleanup only saved a small amount, so startup bitmap residency is still the meaningful win.
- Most bitmaps in this app are only visible in specific states, so deferring creation until first use should help overall heap pressure.
Pattern
static GBitmap *s_icon;
static GColor s_icon_palette[2];
static void ensure_icon_loaded(void) {
if (!s_icon) {
s_icon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ICON);
gbitmap_set_palette(s_icon, s_icon_palette, false);
}
}
static void maybe_unload_icon(bool should_show) {
if (!should_show && s_icon) {
gbitmap_destroy(s_icon);
s_icon = NULL;
}
}
static void layer_update_proc(Layer *layer, GContext *ctx) {
bool should_show = should_show_icon();
if (!should_show) {
maybe_unload_icon(false);
return;
}
ensure_icon_loaded();
graphics_draw_bitmap_in_rect(ctx, s_icon, ICON_FRAME);
}
static void state_changed_callback(bool active) {
layer_mark_dirty(s_icon_layer);
maybe_unload_icon(active);
}
This pattern fits state-driven icons like Bluetooth connected/disconnected, battery charging, and quiet time.
Summary
Rationale
Pattern
This pattern fits state-driven icons like Bluetooth connected/disconnected, battery charging, and quiet time.