Separate the final value from the peak
The final traced size was 1,277 bytes. The retained peak was 4,195,638 bytes. Both came from the same read, after a temporary 4 MiB bytearray had been released. A small value at the end did not describe the largest traced allocation footprint during that interval.[3][4]
This is one actual local CPython 3.9.6 observation using tracemalloc, not a GPU measurement or an invented timing trace. The three cases and their allocation sizes were declared before the run. All twelve current/peak pairs and all ten selected checks are retained in the download.[3][4]
- Same read, different questions: Current describes live traced blocks; peak retains the largest recorded traced size in its interval.
Keep the counter interval and object lifetime
Each case starts a separate tracing session in the same process. We allocate a 1 KiB bytearray and keep it alive through the final read. After recording the pre-reset pair, reset_peak starts a new peak interval without freeing the baseline or clearing its traces. The before, during and after reads use that interval.[3][4]
The transient case allocates a 4 MiB payload: 4,194,304 configured bytes. During the held allocation, current traced memory is 4,195,582 bytes. We clear the payload reference before the after read. Current traced memory falls to 1,277 bytes, while the retained peak is 4,195,638 bytes. The payload is absent from the final live object state but remains represented in the peak counter.[4][3]
The held case is a positive control. It allocates the same payload and retains it through the after read. Final current and peak are both 4,195,638 bytes. The no-extra-payload control ends at 1,249 bytes for both counters. It still holds the baseline and includes observation bookkeeping; its name does not mean zero total memory.[4][3]
The differences are deliberately not asserted to equal the payload size exactly. Python object overhead and the retained counter tuples are traced too. For example, the transient after peak is 56 bytes above its during current reading. The program reports those raw values instead of treating instrumentation as invisible.[4][3]
All twelve counter pairs from the original CPython 3.9.6 run. One MiB is 1,048,576 bytes.
| Case | Read point | Current bytes | Peak bytes |
|---|---|---|---|
| No extra payload | pre reset | 1081 | 1081 |
| No extra payload | before | 1137 | 1137 |
| No extra payload | during | 1193 | 1193 |
| No extra payload | after | 1249 | 1249 |
| Transient 4 MiB | pre reset | 1081 | 1081 |
| Transient 4 MiB | before | 1137 | 1137 |
| Transient 4 MiB | during | 4195582 | 4195582 |
| Transient 4 MiB | after | 1277 | 4195638 |
| Held 4 MiB | pre reset | 1081 | 1081 |
| Held 4 MiB | before | 1137 | 1137 |
| Held 4 MiB | during | 4195582 | 4195582 |
| Held 4 MiB | after | 4195638 | 4195638 |
- Each case holds a 1,024-byte baseline through after. The peak is reset between pre-reset and before.
- Only the held case keeps its extra payload through after. Read tuples and bookkeeping also contribute.
Use the documented counter semantics
The Python documentation defines get_traced_memory as current and peak sizes of traced memory blocks. It also explains that reset_peak changes the recorded peak without clearing traces. This demonstration uses those documented semantics. It does not establish the process resident set, complete native or C-extension allocations, allocator-reserved memory, or GPU memory.[1][2]
The ten checks cover complete records, valid counter pairs, peak monotonicity within each reset interval, baseline coverage, the transient drop, the retained peak, the held-payload control, a coarse no-large-payload bound and cleanup. They are selected checks of three designed cases, not independent samples, exhaustive validation or a confidence interval.[3][4]
- Keep the measurement boundary: Python allocation tracing is not whole-process RSS or GPU memory.
Keep the measurement boundary
When reporting memory, name the counter and the interval. State whether large objects are still held at the final read and whether tracing began before their allocation. Report a retained peak when the question concerns the largest traced footprint. Do not turn this small CPU example into an OOM threshold, hardware-fit guarantee, provider comparison or training result.[3][5]
- Attach the counter definition, reset boundary and object lifetime to each reported memory value.
Sources
- Python tracemalloc: current, peak and reset semantics docs.python.org
- Python tracemalloc: reset_peak docs.python.org
- MIT proof and complete saved output data.nodus-compute.ai
- Saved result JSON data.nodus-compute.ai
- Source and saved-result provenance data.nodus-compute.ai
- Vector figure data.nodus-compute.ai
