A developer encountered out-of-memory errors when running Django's migrate command on Python 3.14, caused by the new incremental garbage collection algorithm failing to keep up with the many reference cycles created by Django's ORM during migrations. Investigation using Memray and custom debugging hooks confirmed no new references were being created — the incremental GC simply wasn't collecting fast enough. The workaround was to subclass Django's migrate command and call gc.collect() after each migration. This story serves as supporting evidence for the Python core team's decision to revert incremental GC in Python 3.14.5.
Table of contents
Python 3.14’s incremental garbage collectionThe problemInitial investigationThe workaroundFinSort: