summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-06-28 10:39:12 -0700
committerScott Shawcroft <scott@tannewt.org>2018-07-03 05:45:50 -0700
commit9de611c056e06684dfa9e5fb4c5fd2f4df579046 (patch)
tree685c322b89555435fe3db673cacdfc7b83a46c15
parent519287550c184db3c3843f10e27111a006fec4b1 (diff)
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
-rwxr-xr-x[-rw-r--r--]py/builtinimport.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 9f7d34dca..c1437da4c 100644..100755
--- 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);