Memory leak using Pin (callback)
-
Hello,
LOPY 1.7.9.b3.
If you run this piece of code you will see that memory is decreasing ... in the end it stops with 'MemoryError: memory allocation failed' . Comparing to timer memory leak issue, I believe there is ALWAYS a LEAK when you are using function callbacks.
import gc import utime from machine import Pin class Object: def __init__(self): print ("Object INIT ", self) def start(self): def _call(arg): print('PIN changed') self._analogPin=Pin('P15',mode=Pin.IN,pull=Pin.PULL_UP) self._analogPin.callback(Pin.IRQ_FALLING , _call) def __del__(self): print ("Object DEL ", self) def stop(self): self._analogPin.callback(Pin.IRQ_FALLING , None) del self._analogPin self._analogPin = None print("Start memory %s" %(gc.mem_free())) SLEEP = 0.1 gc.enable() while True: obj = Object() obj.start() utime.sleep(SLEEP) obj.stop() del obj obj = None gc.collect() print("\t\tmemory %s" %(gc.mem_free()))
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