|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | import warnings |
| 4 | +from array import array |
4 | 5 | from inspect import isabstract |
5 | 6 | from typing import Any |
6 | 7 | import linecache |
@@ -93,24 +94,20 @@ def runtest_refleak(test_name, test_func, |
93 | 94 | for obj in abc.__subclasses__() + [abc]: |
94 | 95 | abcs[obj] = _get_dump(obj)[0] |
95 | 96 |
|
96 | | - # bpo-31217: Integer pool to get a single integer object for the same |
97 | | - # value. The pool is used to prevent false alarm when checking for memory |
98 | | - # block leaks. Fill the pool with values in -1000..1000 which are the most |
99 | | - # common (reference, memory block, file descriptor) differences. |
100 | | - int_pool = {value: value for value in range(-1000, 1000)} |
101 | | - def get_pooled_int(value): |
102 | | - return int_pool.setdefault(value, value) |
103 | | - |
104 | 97 | warmups = hunt_refleak.warmups |
105 | 98 | runs = hunt_refleak.runs |
106 | 99 | filename = hunt_refleak.filename |
107 | 100 | repcount = warmups + runs |
108 | 101 |
|
109 | | - # Pre-allocate to ensure that the loop doesn't allocate anything new |
| 102 | + # Pre-allocate to ensure that the loop doesn't allocate anything new. |
| 103 | + # Store the deltas as raw values in arrays rather than as int objects in |
| 104 | + # lists: each unique delta stored as an object would live until the end of |
| 105 | + # the loop and show up in the following repetition's reference and memory |
| 106 | + # block deltas (gh-75400, gh-155981). |
110 | 107 | rep_range = list(range(repcount)) |
111 | | - rc_deltas = [0] * repcount |
112 | | - alloc_deltas = [0] * repcount |
113 | | - fd_deltas = [0] * repcount |
| 108 | + rc_deltas = array('q', [0]) * repcount |
| 109 | + alloc_deltas = array('q', [0]) * repcount |
| 110 | + fd_deltas = array('q', [0]) * repcount |
114 | 111 | getallocatedblocks = sys.getallocatedblocks |
115 | 112 | gettotalrefcount = sys.gettotalrefcount |
116 | 113 | getunicodeinternedsize = sys.getunicodeinternedsize |
@@ -154,9 +151,9 @@ def get_pooled_int(value): |
154 | 151 | rc_after = gettotalrefcount() |
155 | 152 | fd_after = fd_count() |
156 | 153 |
|
157 | | - rc_deltas[i] = get_pooled_int(rc_after - rc_before) |
158 | | - alloc_deltas[i] = get_pooled_int(alloc_after - alloc_before) |
159 | | - fd_deltas[i] = get_pooled_int(fd_after - fd_before) |
| 154 | + rc_deltas[i] = rc_after - rc_before |
| 155 | + alloc_deltas[i] = alloc_after - alloc_before |
| 156 | + fd_deltas[i] = fd_after - fd_before |
160 | 157 |
|
161 | 158 | if not quiet: |
162 | 159 | # use max, not sum, so total_leaks is one of the pooled ints |
|
0 commit comments