Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit 6e6e509

Browse files
committed
5.2
Fix leak on memory usage
1 parent 3550475 commit 6e6e509

File tree

2 files changed

+80
-62
lines changed

2 files changed

+80
-62
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
"resources": {
3737
"media": [
3838
{
39-
"characterRegex": "[a-z]",
40-
"file": "fonts/ConsSymb.ttf",
41-
"name": "FONT_SYMBOL_16",
39+
"file": "images/menu_icon_spanish_text_watch.png",
40+
"menuIcon": true,
41+
"name": "iconmenu",
4242
"targetPlatforms": null,
43-
"type": "font"
43+
"type": "bitmap"
4444
},
4545
{
4646
"file": "fonts/weatherfontcustom2.ttf",
@@ -49,16 +49,15 @@
4949
"type": "font"
5050
},
5151
{
52-
"file": "images/menu_icon_spanish_text_watch.png",
53-
"menuIcon": true,
54-
"name": "iconmenu",
52+
"file": "fonts/Gotham Light.otf",
53+
"name": "FONT_GLIGHT_16",
5554
"targetPlatforms": null,
56-
"type": "bitmap"
55+
"type": "font"
5756
},
5857
{
5958
"characterRegex": "[a-z' UV\u00f6\u00fc]",
6059
"file": "fonts/Gotham Light.otf",
61-
"name": "FONT_GLIGHT_30",
60+
"name": "FONT_GLIGHT_39",
6261
"targetPlatforms": null,
6362
"trackingAdjust": -2,
6463
"type": "font"
@@ -74,21 +73,21 @@
7473
{
7574
"characterRegex": "[a-z' UV\u00f6\u00fc]",
7675
"file": "fonts/Gotham Light.otf",
77-
"name": "FONT_GLIGHT_39",
76+
"name": "FONT_GLIGHT_30",
7877
"targetPlatforms": null,
7978
"trackingAdjust": -2,
8079
"type": "font"
8180
},
8281
{
83-
"file": "fonts/Gotham Light.otf",
84-
"name": "FONT_GLIGHT_16",
82+
"file": "fonts/Gotham Bold.otf",
83+
"name": "FONT_GBOLD_16",
8584
"targetPlatforms": null,
8685
"type": "font"
8786
},
8887
{
8988
"characterRegex": "[a-z' UV\u00f6\u00fc]",
9089
"file": "fonts/Gotham Bold.otf",
91-
"name": "FONT_GBOLD_30",
90+
"name": "FONT_GBOLD_39",
9291
"targetPlatforms": null,
9392
"trackingAdjust": -1,
9493
"type": "font"
@@ -104,14 +103,15 @@
104103
{
105104
"characterRegex": "[a-z' UV\u00f6\u00fc]",
106105
"file": "fonts/Gotham Bold.otf",
107-
"name": "FONT_GBOLD_39",
106+
"name": "FONT_GBOLD_30",
108107
"targetPlatforms": null,
109108
"trackingAdjust": -1,
110109
"type": "font"
111110
},
112111
{
113-
"file": "fonts/Gotham Bold.otf",
114-
"name": "FONT_GBOLD_16",
112+
"characterRegex": "[a-z]",
113+
"file": "fonts/ConsSymb.ttf",
114+
"name": "FONT_SYMBOL_16",
115115
"targetPlatforms": null,
116116
"type": "font"
117117
}
@@ -129,5 +129,5 @@
129129
"watchface": true
130130
}
131131
},
132-
"version": "5.1.0"
132+
"version": "5.2.0"
133133
}

src/c/main.c

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -828,44 +828,30 @@ static void prv_window_load(Window *window) {
828828
}
829829
// Window Unload event
830830
static void prv_window_unload(Window *window) {
831-
layer_destroy(back_layer);
831+
layer_destroy(back_layer);
832+
window_destroy(s_main_window);
833+
text_layer_destroy(line1.currentLayer);
834+
text_layer_destroy(line1.nextLayer);
835+
text_layer_destroy(line2.currentLayer);
836+
text_layer_destroy(line2.nextLayer);
837+
text_layer_destroy(line3.currentLayer);
838+
text_layer_destroy(line3.nextLayer);
839+
layer_destroy(scroll);
840+
fonts_unload_custom_font(FontCond);
841+
fonts_unload_custom_font(Bold);
842+
fonts_unload_custom_font(BoldReduced1);
843+
fonts_unload_custom_font(BoldReduced2);
844+
fonts_unload_custom_font(Light);
845+
fonts_unload_custom_font(LightReduced1);
846+
fonts_unload_custom_font(LightReduced2);
847+
fonts_unload_custom_font(FontWDay);
848+
fonts_unload_custom_font(FontDate);
849+
fonts_unload_custom_font(FontSymbol);
832850
}
833-
static void prv_init(void) {
834-
prv_load_settings();
835-
836-
//Starting loop at 0
837-
s_loop=0;
838-
s_countdown=settings.UpSlider;
839-
//Clean vars
840-
strcpy(tempstring, "");
841-
strcpy(condstringday, "");
842-
strcpy(condstringnight, "");
843-
844-
845-
// Listen for AppMessages
846-
app_message_register_inbox_received(prv_inbox_received_handler);
847-
app_message_open(256, 256);
848851

849-
// Configure main window
850-
s_main_window = window_create();
851-
window_set_window_handlers(s_main_window, (WindowHandlers) {
852-
.load = prv_window_load,
853-
.unload = prv_window_unload,
854-
});
852+
void main_window_push() {
853+
s_main_window = window_create();
855854

856-
// Load fonts
857-
Bold=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_39));
858-
BoldReduced1=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_34));
859-
BoldReduced2=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_30));
860-
Light=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_39));
861-
LightReduced1=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_34));
862-
LightReduced2=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_30));
863-
FontCond=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_WICON_26));
864-
FontWDay=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_16));
865-
FontDate=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_16));
866-
FontSymbol =fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SYMBOL_16));
867-
868-
window_stack_push(s_main_window, true);
869855
Layer *root = window_get_root_layer(s_main_window);
870856

871857
//Set bounds and offsets
@@ -898,9 +884,48 @@ static void prv_init(void) {
898884
layer_add_child(scroll, (Layer *)line2.nextLayer);
899885
layer_add_child(scroll, (Layer *)line3.currentLayer);
900886
layer_add_child(scroll, (Layer *)line3.nextLayer);
901-
887+
888+
// Configure main window
889+
window_set_window_handlers(s_main_window, (WindowHandlers) {
890+
.load = prv_window_load,
891+
.unload = prv_window_unload,
892+
});
893+
894+
895+
window_stack_push(s_main_window, true);
896+
}
897+
902898

899+
static void prv_init(void) {
900+
prv_load_settings();
901+
902+
//Starting loop at 0
903+
s_loop=0;
904+
s_countdown=settings.UpSlider;
905+
//Clean vars
906+
strcpy(tempstring, "");
907+
strcpy(condstringday, "");
908+
strcpy(condstringnight, "");
909+
910+
911+
// Listen for AppMessages
912+
app_message_register_inbox_received(prv_inbox_received_handler);
913+
app_message_open(256, 256);
914+
915+
// Load fonts
916+
Bold=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_39));
917+
BoldReduced1=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_34));
918+
BoldReduced2=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_30));
919+
Light=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_39));
920+
LightReduced1=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_34));
921+
LightReduced2=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_30));
922+
FontCond=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_WICON_26));
923+
FontWDay=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GBOLD_16));
924+
FontDate=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GLIGHT_16));
925+
FontSymbol =fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SYMBOL_16));
903926

927+
main_window_push();
928+
904929
// Configure text time on init
905930
time_t now = time(NULL);
906931
struct tm *t = localtime(&now);
@@ -935,16 +960,9 @@ static void prv_init(void) {
935960
}
936961
}
937962
static void prv_deinit(void) {
938-
window_destroy(s_main_window);
963+
939964
tick_timer_service_unsubscribe();
940-
app_message_deregister_callbacks(); //Destroy the callbacks for clean up
941-
text_layer_destroy(line1.currentLayer);
942-
text_layer_destroy(line1.nextLayer);
943-
text_layer_destroy(line2.currentLayer);
944-
text_layer_destroy(line2.nextLayer);
945-
text_layer_destroy(line3.currentLayer);
946-
text_layer_destroy(line3.nextLayer);
947-
layer_destroy(scroll);
965+
app_message_deregister_callbacks(); //Destroy the callbacks for clean up
948966
}
949967
int main(void) {
950968
prv_init();

0 commit comments

Comments
 (0)