diff --git a/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m b/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m index 9fd83eb..41ac8c7 100644 --- a/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m +++ b/{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m @@ -334,9 +334,14 @@ int main(int argc, char *argv[]) { ret = -7; } @finally { - Py_Finalize(); + // Force a full GC pass while the interpreter is alive and a pool is + // in place, so Python drops any ObjC references and anything + // autoreleased lands in this pool. + PyGC_Collect(); } } + // Autorelease pool is drained; any Python -dealloc has run against a live interpreter. + Py_Finalize(); exit(ret); return ret;