Force as many objects as possible to be collected. In non-CPython implementations of Python, this is needed because timely deallocation is not guaranteed by the garbage collector. (Even in CPython this can be the case in case of reference cycles.) This means that __del__ methods m
()
| 935 | |
| 936 | |
| 937 | def gc_collect(): |
| 938 | """Force as many objects as possible to be collected. |
| 939 | |
| 940 | In non-CPython implementations of Python, this is needed because timely |
| 941 | deallocation is not guaranteed by the garbage collector. (Even in CPython |
| 942 | this can be the case in case of reference cycles.) This means that __del__ |
| 943 | methods may be called later than expected and weakrefs may remain alive for |
| 944 | longer than expected. This function tries its best to force all garbage |
| 945 | objects to disappear. |
| 946 | """ |
| 947 | import gc |
| 948 | gc.collect() |
| 949 | gc.collect() |
| 950 | gc.collect() |
| 951 | |
| 952 | @contextlib.contextmanager |
| 953 | def disable_gc(): |
searching dependent graphs…