Two kinds of memory claim#
Automated reviewers raise two different claims under this heading. The first is about state that lives as long as the process: a dictionary keyed by request, a list of timestamps, a cache with no eviction. Its size depends on how often entries arrive and what removes them. Python's own deque documentation draws the line: "If maxlen is not specified or is None, deques may grow to an arbitrary length." That says what the type allows. Whether your deque grows depends on the code that removes entries.
The second is about one operation that holds its whole input at once: reading a file with read(), building a list from a query or materializing every object a delete touches. Its size depends on the largest input, not on uptime. The two need different evidence.
A whole-input claim, fixed and then measured#
In August 2026, a NetBox pull request fixed an issue where deleting scripts with many recorded jobs caused memory use high enough to exhaust the server. The description explained the cause: "Django's deletion collector loads every related Job into memory". Pull request Django's documentation confirms the mechanism: "Django needs to fetch objects into memory to send signals and handle cascades", and only when there are no cascades and no signals can it "take a fast-path and delete objects without fetching into memory." QuerySet.delete()
The first version deleted jobs in batches. Its automated Claude review pointed out that each batch still loaded full job rows, including their output and logs: "With multi-MB script output that's still hundreds of MB per batch." Claude review The author changed the batch to load only primary keys, and checked the result: "Confirmed via captured SQL that the delete's initial SELECT pulls only id". Author's reply
The next review noted that the batch size had been chosen for full rows and no longer fit: "A batch is now 100 integers." Claude review Here the author measured instead of guessing: "I benchmarked a 200k-job deletion across 100/1000/5000; 1000 was fastest and peak memory was flat across all three." They added that "a single unbatched delete was the only one that spiked". Author's reply The merged helper, from the pull request merged on 11 August 2026:
job_pks = job_queryset.order_by('pk').values_list('pk', flat=True)
# Re-slice the queryset each iteration: it re-queries after each batch delete, so the
# remaining set shrinks and the loop terminates (do not hoist this into a cursor).
while pks := list(job_pks[:JOB_DELETE_BATCH_SIZE]):
# only('pk'): the batch still can't fast-delete, so each Job in the batch is instantiated;
# loading just the PK avoids pulling the large data/log_entries payloads into memory.
jobs.filter(pk__in=pks).only('pk').delete()
The first comment named a real cost and the second an assumption the fix had made obsolete. Captured SQL settled the first, and a measurement at 200,000 jobs settled the second.
A long-lived collection that already had a bound#
A Home Assistant pull request, opened in August 2026, made the Netatmo integration count API calls over a trailing hour with a deque of timestamps. Copilot said: "Pruning of self._calls only happens when _calls_in_the_last_hour() is invoked. Since timestamps are appended in async_fetch_data(), it's possible for the deque to grow without being pruned if fetches occur without passing through async_update() often enough (e.g., via force-update paths)." Copilot review
The claim is true about the call sites and wrong about the bound. At the merge commit, async_update() is not only reached through fetches. async_setup() schedules it with async_track_time_interval every SCAN_INTERVAL, which is 60 seconds, and every run calls _calls_in_the_last_hour(), which drops timestamps older than an hour. Merged coordinator Whatever path adds calls, while the integration is loaded the deque never holds more than the calls of about the last 61 minutes. A short simulation of that schedule confirms the bound:
from collections import deque
def peak(gap, hours=6):
calls, peak_len = deque(), 0
for t in range(0, hours * 3600):
if t % gap == 0:
calls.append(t)
if t % 60 == 0:
while calls and calls[0] < t - 3600:
calls.popleft()
peak_len = max(peak_len, len(calls))
return peak_len
for gap in (9, 1): # 400 calls an hour, and one call every second
print(f"one call every {gap}s: peak {peak(gap)} entries")
It prints a peak of 407 entries at 400 calls an hour, the integration's development rate limit, and 3,660 at one call every second. The maintainer who later approved wrote: "Your replies to the Copilot threads hold up." Maintainer's review The author's replies sit in resolved threads that the page does not show, so I have not read them. The pull request merged on 19 October 2026 without a change to the pruning.
Decide by what removes entries#
| What you find | Decision |
|---|---|
| Nothing ever removes entries, and keys come from requests, users or time | Change. Add maxlen, an LRU or a time-to-live, and test the size after many inserts |
| Removal runs on a timer or on every pass of a loop that always runs | Dismiss. Give the bound as rate times window |
| Removal runs only on a path that may stop running | Change, or add a test that shows the bound without that path |
| One operation loads a whole file, response or result set | Measure peak memory at the largest expected input, with tracemalloc or the process's resident size. Stream or batch it if that peak grows with data |
For a timed removal, the arithmetic is the reply: the window, the removal interval and the highest realistic rate. For a whole-input load, the measurement is the reply, as in the NetBox thread, and a query with no limit is often where that input comes from.