You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code checks if self._sample has been initialised and then assigns a new buffer to self._samples (note plural!). It looks like a typo which wasn't picked up by linting as _sample is used for playing sounds over tiny speaker.
This causes a new buffer to be created on each read of the sound_level property. This doesn't leak but it is inefficient and may cause problems for applications with a small amount of (fragmented) remaining memory...
Once this is fixed, a single read of sound_level may be beneficial at the start of a program that's tight on memory or encountering MemoryError: memory allocation failed, allocating 640 bytes exceptions later when sound_level is used repeatedly. This approach aligns with the advice in Adafruit Learn: Memory-saving tips for CircuitPython: Memory: Reducing fragmentation.
Advanced programmers: Allocate a large memory buffer early in the life of your code and reuse the same memory buffer through your program.
The text was updated successfully, but these errors were encountered:
kevinjwalters
pushed a commit
to kevinjwalters/Adafruit_CircuitPython_CLUE
that referenced
this issue
Jan 23, 2022
Looks like this got solved (at least in part) by PR #54, is this fixed now? Or is it worth specifically calling gc.collect() after self._samples = array.array("H", [0] * 160)?
The code checks if
self._sample
has been initialised and then assigns a new buffer toself._samples
(note plural!). It looks like a typo which wasn't picked up by linting as_sample
is used for playing sounds over tiny speaker.Adafruit_CircuitPython_CLUE/adafruit_clue.py
Lines 815 to 816 in 670355e
This causes a new buffer to be created on each read of the
sound_level
property. This doesn't leak but it is inefficient and may cause problems for applications with a small amount of (fragmented) remaining memory...Once this is fixed, a single read of
sound_level
may be beneficial at the start of a program that's tight on memory or encounteringMemoryError: memory allocation failed, allocating 640 bytes
exceptions later whensound_level
is used repeatedly. This approach aligns with the advice in Adafruit Learn: Memory-saving tips for CircuitPython: Memory: Reducing fragmentation.The text was updated successfully, but these errors were encountered: