A user reports that deleting list elements by index with del does not shrink the underlying array, causing memory to remain large, while popping elements correctly reduces memory usage. Reproducible example: seq = list(range(1000)) yields sys.getsizeof(seq) == 8056; after seq.pop() repeated 1000 times getsizeof(seq) == 56, but after repeating del seq[-1] 1000 times getsizeof(seq) remains 8056. The behavior contrasts the expected reallocation on shrink and demonstrates a clear divergence between pop() and del-by-index semantics with measurable memory impact.
The report notes this is likely a regression tied to an earlier change (#115605) where list_ass_slice() was replaced by a separate implementation, and it was tested on CPython 3.13-3.15 and main on Linux. Labels mark it as a bug, performance/resource-usage issue, and refactor-related. Two linked pull requests aim to fix the problem: one forces reallocation of the list’s array when deleting by index (#158602) and another avoids unnecessary reallocation when shrinking very small lists (#158787). The issue remains open and unassigned.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.