<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to solve the UI memory leak?]]></title><description><![CDATA[<p dir="auto">I used UIFlow2.3.3 to develop a simple UI demo. There is only one image widget to switch 2 JPG images every second. When I monitor the memory with gc.mem_free, I found the memory reduced continiously. And finally, the image switching was stop, but the loop was running. I wonder how to solve the UI memory leak? Here is my python code:<br />
import os, sys, io<br />
import M5<br />
from M5 import *<br />
import time</p>
<p dir="auto">image0 = None<br />
oldData14 = None</p>
<p dir="auto">ImgFlag = None</p>
<p dir="auto">def setup():<br />
global image0, oldData14, ImgFlag</p>
<p dir="auto">M5.begin()<br />
Widgets.fillScreen(0x000000)<br />
image0 = Widgets.Image("/flash/res/img/default.jpg", 0, 0, scale_x=1, scale_y=1)</p>
<p dir="auto">image0.setImage("/flash/res/img/RotaryBGBacklight.jpg")<br />
ImgFlag = 0</p>
<p dir="auto">def loop():<br />
global image0, oldData14, ImgFlag<br />
M5.update()<br />
if (time.localtime())[5] != oldData14:<br />
PrintFreeMem()<br />
oldData14 = (time.localtime())[5]<br />
if ImgFlag == 0:<br />
image0.setImage("/flash/res/img/RotaryBGBT.jpg")<br />
ImgFlag = 1<br />
elif ImgFlag == 1:<br />
image0.setImage("/flash/res/img/RotaryBGBacklight.jpg")<br />
ImgFlag = 0<br />
else:<br />
pass</p>
<p dir="auto">def PrintFreeMem():<br />
print("Free mem:", gc.mem_free())</p>
<p dir="auto">if <strong>name</strong> == '<strong>main</strong>':<br />
try:<br />
setup()<br />
while True:<br />
loop()<br />
except (Exception, KeyboardInterrupt) as e:<br />
try:<br />
from utility import print_error_msg<br />
print_error_msg(e)<br />
except ImportError:<br />
print("please update to latest firmware")</p>
<p dir="auto">And my UIFlow2 design:<br />
<img src="/assets/uploads/files/1755657692748-e4d05eba-b6dc-4581-9493-115e830e4262-image.png" alt="e4d05eba-b6dc-4581-9493-115e830e4262-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.m5stack.com/topic/7766/how-to-solve-the-ui-memory-leak</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 08:19:56 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7766.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Aug 2025 02:42:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to solve the UI memory leak? on Fri, 22 Aug 2025 00:59:35 GMT]]></title><description><![CDATA[<p dir="auto">I tested more UI design. And I found that the memory leak only happens when I use image component and switch images frequently. Is that a UIFlow2.3.3 bug or my design is incorrect?</p>
]]></description><link>https://community.m5stack.com/post/29812</link><guid isPermaLink="true">https://community.m5stack.com/post/29812</guid><dc:creator><![CDATA[zhumingqi]]></dc:creator><pubDate>Fri, 22 Aug 2025 00:59:35 GMT</pubDate></item></channel></rss>