Skip to content

Commit 4637855

Browse files
authored
Merge pull request #6406 from dhalbert/restore-gc-collect-on-import
Restore automatic gc_collect() after an import
2 parents 036a582 + 4487f61 commit 4637855

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ msgstr ""
10221022
msgid "Failed to acquire mutex, err 0x%04x"
10231023
msgstr ""
10241024

1025+
#: shared-module/rgbmatrix/RGBMatrix.c
1026+
msgid "Failed to allocate %q buffer"
1027+
msgstr ""
1028+
10251029
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
10261030
#: ports/raspberrypi/common-hal/busio/UART.c
10271031
msgid "Failed to allocate RX buffer"

py/builtinimport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name,
455455
// not a package. This will be caught on the next iteration
456456
// because the file will not exist.
457457
}
458+
459+
// Loading a module thrashes the heap significantly so we explicitly clean up
460+
// afterwards.
461+
gc_collect();
458462
}
459463

460464
if (outer_module_obj != MP_OBJ_NULL && VERIFY_PTR(MP_OBJ_TO_PTR(outer_module_obj))) {

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self,
123123
mp_raise_ValueError(translate("Invalid argument"));
124124
break;
125125
case PROTOMATTER_ERR_MALLOC:
126-
mp_raise_msg(&mp_type_MemoryError, NULL);
126+
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate %q buffer"), MP_QSTR_RGBMatrix);
127127
break;
128128
default:
129129
mp_raise_msg_varg(&mp_type_RuntimeError,

0 commit comments

Comments
 (0)