Skip to content

Commit 9de611c

Browse files
committed
Always collect after an import
Imports generate a lot of garbage so cleaning it up immediately reduces the likelihood longer lived data structures don't end up in the middle of the heap. Fixes adafruit#856
1 parent 5192875 commit 9de611c

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

py/builtinimport.c

100644100755
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "py/compile.h"
3333
#include "py/gc_long_lived.h"
34+
#include "py/gc.h"
3435
#include "py/objmodule.h"
3536
#include "py/persistentcode.h"
3637
#include "py/runtime.h"
@@ -468,6 +469,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
468469
// (the module that was just loaded) is not a package. This will be caught
469470
// on the next iteration because the file will not exist.
470471
}
472+
473+
// Loading a module thrashes the heap significantly so we explicitly clean up
474+
// afterwards.
475+
gc_collect();
471476
}
472477
if (outer_module_obj != MP_OBJ_NULL) {
473478
qstr s = qstr_from_strn(mod_str + last, i - last);

0 commit comments

Comments
 (0)