From 9de611c056e06684dfa9e5fb4c5fd2f4df579046 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 28 Jun 2018 10:39:12 -0700 Subject: [PATCH] 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 #856 --- py/builtinimport.c | 5 +++++ 1 file changed, 5 insertions(+) mode change 100644 => 100755 py/builtinimport.c diff --git a/py/builtinimport.c b/py/builtinimport.c old mode 100644 new mode 100755 index 9f7d34dcae..c1437da4c2 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -31,6 +31,7 @@ #include "py/compile.h" #include "py/gc_long_lived.h" +#include "py/gc.h" #include "py/objmodule.h" #include "py/persistentcode.h" #include "py/runtime.h" @@ -468,6 +469,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { // (the module that was just loaded) is not a package. This will be caught // on the next iteration because the file will not exist. } + + // Loading a module thrashes the heap significantly so we explicitly clean up + // afterwards. + gc_collect(); } if (outer_module_obj != MP_OBJ_NULL) { qstr s = qstr_from_strn(mod_str + last, i - last);