aboutsummaryrefslogtreecommitdiff
path: root/py/gc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-31 23:10:48 +1000
committerDamien George <damien.p.george@gmail.com>2018-06-12 11:55:29 +1000
commit522ea80f06a80fd799bd57de351373ceaeeae325 (patch)
treea0759e8d15d1643cc930c523b5fb4b5aeed7aad7 /py/gc.c
parent8fb95d652066b38e0dbb4fa5433de49eb601bdfe (diff)
py/gc: Add gc_sweep_all() function to run all remaining finalisers.
This patch adds the gc_sweep_all() function which does a garbage collection without tracing any root pointers, so frees all the memory, and most importantly runs any remaining finalisers. This helps primarily for soft reset: it will close any open files, any open sockets, and help to get the system back to a clean state upon soft reset.
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/gc.c b/py/gc.c
index e92b81ece..0fc43ef49 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -362,6 +362,13 @@ void gc_collect_end(void) {
GC_EXIT();
}
+void gc_sweep_all(void) {
+ GC_ENTER();
+ MP_STATE_MEM(gc_lock_depth)++;
+ MP_STATE_MEM(gc_stack_overflow) = 0;
+ gc_collect_end();
+}
+
void gc_info(gc_info_t *info) {
GC_ENTER();
info->total = MP_STATE_MEM(gc_pool_end) - MP_STATE_MEM(gc_pool_start);