GC to reduce memory fragmentation
This commit is contained in:
parent
0b4b98f5fb
commit
9e8c9c3669
BIN
kmk/.DS_Store
vendored
Normal file
BIN
kmk/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
from gc import collect
|
||||
from micropython import const
|
||||
|
||||
import kmk.handlers.stock as handlers
|
||||
@ -666,6 +667,7 @@ def make_key(code=None, names=tuple(), type=KEY_SIMPLE, **kwargs): # NOQA
|
||||
All **kwargs are passed to the Key constructor
|
||||
'''
|
||||
|
||||
collect()
|
||||
global NEXT_AVAILABLE_KEY
|
||||
|
||||
if type == KEY_SIMPLE:
|
||||
|
@ -3,6 +3,7 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from gc import collect
|
||||
from supervisor import ticks_ms
|
||||
|
||||
from kmk.consts import UnicodeMode
|
||||
@ -444,18 +445,25 @@ class KMKKeyboard:
|
||||
self.hid_type = hid_type
|
||||
self.secondary_hid_type = secondary_hid_type
|
||||
|
||||
# Collect is run to keep memory fragmentation down.
|
||||
collect()
|
||||
self._init_sanity_check()
|
||||
collect()
|
||||
self._init_hid()
|
||||
collect()
|
||||
self._init_matrix()
|
||||
collect()
|
||||
self._init_coord_mapping()
|
||||
|
||||
for module in self.modules:
|
||||
collect()
|
||||
try:
|
||||
module.during_bootup(self)
|
||||
except Exception as err:
|
||||
if debug.enabled:
|
||||
debug(f'Failed to load module {module}: {err}')
|
||||
for ext in self.extensions:
|
||||
collect()
|
||||
try:
|
||||
ext.during_bootup(self)
|
||||
except Exception as err:
|
||||
@ -482,11 +490,11 @@ class KMKKeyboard:
|
||||
|
||||
if self.secondary_matrix_update:
|
||||
self.matrix_update_queue.append(self.secondary_matrix_update)
|
||||
self.secondary_matrix_update = None
|
||||
del self.secondary_matrix_update
|
||||
|
||||
if self.matrix_update:
|
||||
self.matrix_update_queue.append(self.matrix_update)
|
||||
self.matrix_update = None
|
||||
del self.matrix_update
|
||||
|
||||
# only handle one key per cycle.
|
||||
if self.matrix_update_queue:
|
||||
@ -513,3 +521,5 @@ class KMKKeyboard:
|
||||
|
||||
if self.state_changed:
|
||||
self._print_debug_cycle()
|
||||
|
||||
collect()
|
||||
|
Loading…
Reference in New Issue
Block a user