Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Diagnosing a potential memory leak?

    Scheduled Pinned Locked Moved SiPy
    3 Posts 1 Posters 48 Views 1 Watching
    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.
    • L Offline
      Lennac
      last edited by

      The program I'm running proceeds without issue for several minutes (probably close to 10 minutes, I haven't done a closely monitored test of when the error arises). Anyway, after running for a period of time, I am give a memory allocation error of 4096 bytes.

      while(1):
          time.sleep(2) # sleep for two seconds as per DHT specifications
          result = th.read() # read values from DHT
          if result.is_valid():
              pycom.rgbled(0x001000) # green - onboard data read confirmation
              print('Temperature: {:3.2f}'.format(result.temperature/1.0)) # print temp to console
              print('Humidity: {:3.2f}'.format(result.humidity/1.0)) # print rh to console
          full, ir = tsl.get_full_luminosity()  # read raw values (full spectrum and ir spectrum)
          lux = tsl.calculate_lux(full, ir)  # convert raw values to lux
          print('Lux: ' + str(lux) + ' Lumens')
          display = 'Temperature: {:3.2f}\nHumidity: {:3.2f}\nLux: {:3.2f}'.format(result.temperature/1.0,result.humidity/1.0,lux)
          lcd.clear()
          lcd.putstr(display)
          gc.mem_free() # memory management
          gc.collect()
      

      The only code I haven't included from main.py is the initialization of my pins.

      If required, I can post the code from my imported library that pinpoints the exact function where the memory allocation error arises. However, since the program does run for a time, I don't think it's an issue with any specific function, but rather that I am not handling my memory efficiently as it depletes over time.

      1 Reply Last reply Reply Quote 0
      • L Offline
        Lennac
        last edited by

        Figured I'd update and answer this question in case anyone runs into a similar issue, the problem was very simply solved by deleting my variables at the end of the while loop:

        del result, full, ir, display
        
        1 Reply Last reply Reply Quote 0
        • L Offline
          Lennac
          last edited by

          Never mind, this merely delayed the issue I was having - which extended my run time from around 10 minutes to several hours. It was able to run without issue for quite a while (I left it overnight) and at some point during the night I encountered the same memory allocation error.

          If anyone has any insight into how I might be able to remedy this, I would really appreciate it.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom