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
|
from micropython import const
|
||||||
|
|
||||||
import kmk.handlers.stock as handlers
|
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
|
All **kwargs are passed to the Key constructor
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
collect()
|
||||||
global NEXT_AVAILABLE_KEY
|
global NEXT_AVAILABLE_KEY
|
||||||
|
|
||||||
if type == KEY_SIMPLE:
|
if type == KEY_SIMPLE:
|
||||||
|
@ -3,6 +3,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
from gc import collect
|
||||||
from supervisor import ticks_ms
|
from supervisor import ticks_ms
|
||||||
|
|
||||||
from kmk.consts import UnicodeMode
|
from kmk.consts import UnicodeMode
|
||||||
@ -444,18 +445,25 @@ class KMKKeyboard:
|
|||||||
self.hid_type = hid_type
|
self.hid_type = hid_type
|
||||||
self.secondary_hid_type = secondary_hid_type
|
self.secondary_hid_type = secondary_hid_type
|
||||||
|
|
||||||
|
# Collect is run to keep memory fragmentation down.
|
||||||
|
collect()
|
||||||
self._init_sanity_check()
|
self._init_sanity_check()
|
||||||
|
collect()
|
||||||
self._init_hid()
|
self._init_hid()
|
||||||
|
collect()
|
||||||
self._init_matrix()
|
self._init_matrix()
|
||||||
|
collect()
|
||||||
self._init_coord_mapping()
|
self._init_coord_mapping()
|
||||||
|
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
|
collect()
|
||||||
try:
|
try:
|
||||||
module.during_bootup(self)
|
module.during_bootup(self)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if debug.enabled:
|
if debug.enabled:
|
||||||
debug(f'Failed to load module {module}: {err}')
|
debug(f'Failed to load module {module}: {err}')
|
||||||
for ext in self.extensions:
|
for ext in self.extensions:
|
||||||
|
collect()
|
||||||
try:
|
try:
|
||||||
ext.during_bootup(self)
|
ext.during_bootup(self)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -482,11 +490,11 @@ class KMKKeyboard:
|
|||||||
|
|
||||||
if self.secondary_matrix_update:
|
if self.secondary_matrix_update:
|
||||||
self.matrix_update_queue.append(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:
|
if self.matrix_update:
|
||||||
self.matrix_update_queue.append(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.
|
# only handle one key per cycle.
|
||||||
if self.matrix_update_queue:
|
if self.matrix_update_queue:
|
||||||
@ -513,3 +521,5 @@ class KMKKeyboard:
|
|||||||
|
|
||||||
if self.state_changed:
|
if self.state_changed:
|
||||||
self._print_debug_cycle()
|
self._print_debug_cycle()
|
||||||
|
|
||||||
|
collect()
|
||||||
|
Loading…
Reference in New Issue
Block a user