🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to solve the UI memory leak?

    UiFlow 2.0
    1
    1
    23
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zhumingqi
      last edited by

      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:
      import os, sys, io
      import M5
      from M5 import *
      import time

      image0 = None
      oldData14 = None

      ImgFlag = None

      def setup():
      global image0, oldData14, ImgFlag

      M5.begin()
      Widgets.fillScreen(0x000000)
      image0 = Widgets.Image("/flash/res/img/default.jpg", 0, 0, scale_x=1, scale_y=1)

      image0.setImage("/flash/res/img/RotaryBGBacklight.jpg")
      ImgFlag = 0

      def loop():
      global image0, oldData14, ImgFlag
      M5.update()
      if (time.localtime())[5] != oldData14:
      PrintFreeMem()
      oldData14 = (time.localtime())[5]
      if ImgFlag == 0:
      image0.setImage("/flash/res/img/RotaryBGBT.jpg")
      ImgFlag = 1
      elif ImgFlag == 1:
      image0.setImage("/flash/res/img/RotaryBGBacklight.jpg")
      ImgFlag = 0
      else:
      pass

      def PrintFreeMem():
      print("Free mem:", gc.mem_free())

      if name == 'main':
      try:
      setup()
      while True:
      loop()
      except (Exception, KeyboardInterrupt) as e:
      try:
      from utility import print_error_msg
      print_error_msg(e)
      except ImportError:
      print("please update to latest firmware")

      And my UIFlow2 design:
      e4d05eba-b6dc-4581-9493-115e830e4262-image.png

      1 Reply Last reply Reply Quote 0
      • First post
        Last post