Apple II memleak analysis notes. - FujiNetWIFI/fujinet-firmware GitHub Wiki
Goal
Fix memory leak when using HTTP protocol adapter with JSON channel mode.
Changes to keys.cpp
key | action |
---|---|
A SINGLE TAP | Heap |
A DOUBLE TAP | Tasks |
Available memory after cold start
15:07:05.542 > Heap: 36492
This is very low.
Initial boot log 2024-05-10
15:19:48.294 > --~--~--~--
15:19:48.294 > FujiNet v1.3 2024-04-26 06:08:28 Started @ 7
15:19:48.294 > Starting heap: 4358276
15:19:48.295 > [src/main.cpp:162] main_setup(): Heap: 212971
15:19:48.297 >
15:19:48.316 > Rev1 Hardware Defined
15:19:48.316 > FujiApple NO3STATE & SPIFIX ENABLED
15:19:48.316 > FujiApple SPI fix ENABLED
15:19:48.318 > Detected Hardware Version: 1.6.1 and up
15:19:48.318 > Safe Reset button ENABLED on GPIO 4
15:19:48.478 > SPIFFS mounted.
15:19:48.552 > SD mounted.
15:19:48.552 > fnConfig::load
15:19:48.552 > Load fnconfig.ini from SD
15:19:48.552 > fopen = /fnconfig.ini : ok
15:19:48.556 > fnConfig::load read 1097 bytes from config file
15:19:48.556 > Reading wifi section
15:19:48.559 > Reading stored wifi section for index: 0
15:19:48.600 > FLASH Config Storage: Enabled
15:19:48.601 > fnConfig::load read 1097 bytes from FLASH config file
15:19:48.602 > FNJSON::ctor()
15:19:48.602 > iwmNetwork::iwmNetwork()
15:19:48.602 >
15:19:48.603 > Config General Boot Mode: 0
15:19:48.603 > FileSystemSPIFFS::filehandler_open /autorun.po rb
15:19:48.673 > new FileHandlerLocal
15:19:48.673 > disk MOUNT /autorun.po
15:19:48.673 >
15:19:48.673 > Media Type POFileHandlerLocal::read
15:19:48.674 >
15:19:48.674 > IWM FujiNet based on SmartportSD v1.15
15:19:48.674 >
15:19:48.675 > FujiNet Hardware timer started
15:19:48.675 > RMT configured for Disk ][ Output
15:19:48.677 > SPI configured for smartport I/O
15:19:48.677 > IWM GPIO configuredAvailable heap: 4228500
15:19:48.679 > Setup complete @ 392 (385ms)
15:19:48.679 > [src/main.cpp:463] main_setup(): Low Heap: 135775
15:19:48.682 >
15:19:48.701 > WiFiManager::start() complete
15:19:48.798 > WiFiManager attempting to connect:
15:19:48.798 > ssid = Cherryhomes
15:19:48.798 > WiFi connect attempt to SSID "Cherryhomes"
15:19:48.800 > WIFI_EVENT_STA_START
15:19:48.800 > esp_wifi_connect returned 0
15:19:50.742 > WIFI_EVENT_STA_CONNECTED
15:19:52.733 > IP_EVENT_STA_GOT_IP
15:19:52.733 > Obtained IP address: 192.168.1.19
15:19:52.733 > SNTP client start
15:19:52.736 > Starting web server on port 80
15:20:26.242 > SNTP time sync event: Fri May 10, 15:20:26 2024 -0500
15:20:44.425 > BUTTON_A: SHORT PRESS
15:20:44.725 > Heap: 36468
MODEM task started at boot.
- This should be changed to start the task on open.
15:22:32.731 > T01 0x3ffbc8e4 (17,17) 30352h 164181174r Ready: fnLoop
15:22:32.731 > T02 0x3ffb2cd4 ( 1, 1) 2432h 40658r Running: fnKeys
15:22:32.732 > T03 0x3ffb35cc ( 0, 0) 1024h 162124660r Ready: IDLE
15:22:32.733 > T04 0x3ffb3d50 ( 0, 0) 1020h 173598r Ready: IDLE
15:22:32.735 > T05 0x3ffbab14 (18,18) 2552h 69749r Blocked: tiT
15:22:32.736 > T06 0x3ffdef60 (10,10) 3264h 40472r Blocked: modemTask
15:22:32.738 > T07 0x3ffb2b60 (10,10) 1476h 45r Blocked: card_detect_int
15:22:32.739 > T08 0x3ffaf8f0 (24,24) 444h 213516r Blocked: ipc0
15:22:32.740 > T09 0x3ffafe74 (24,24) 376h 12208r Blocked: ipc1
15:22:32.742 > T10 0x3fff5308 (12,12) 7172h 1543r Blocked: httpd
15:22:32.743 > T11 0x3ffbbe98 (20,20) 2228h 6841r Blocked: sys_evt
15:22:32.744 > T12 0x3fff6d3c ( 1, 1) 1964h 16807r Blocked: mdns
15:22:32.746 > T13 0x3ffb1b3c (22,22) 3312h 252369r Suspened: esp_timer
15:22:32.747 > T14 0x3ffe3d30 (23,23) 4572h 1738900r Blocked: wifi
15:22:32.747 > T15 0x3ffb46d4 ( 1, 1) 1480h 16r Blocked: Tmr Svc
15:22:32.749 >
15:22:32.749 > CPU MHz: 240
Only open modem task at boot
- With adjustment in this commit: https://github.com/FujiNetWIFI/fujinet-firmware/commit/f4c725106742baf68dce0e9ea3840c34bc8081ab
15:33:21.272 > BUTTON_A: SHORT PRESS
15:33:21.572 > Heap: 73947
Removing MDNS
- Removing mdns_xxxx() calls gives us:
81916
Network device
We allocate a single network device atm, removing this initialization gives us an additional 12K. (Investigate static allocations)
Checking memory usage by set_json_query()
Low heap size is identical at start and end of set_json_query, problem isn't here.