Message198061
| Author |
serhiy.storchaka |
| Recipients |
pitrou, rhettinger, serhiy.storchaka |
| Date |
2013年09月19日.11:48:13 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1379591293.2.0.269395220303.issue19048@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Thy are visible by calling gc.get_referents(). High-level function can use this to count recursive size of objects.
>>> import sys, gc, itertools
>>> def gettotalsizeof(*args, seen=None):
... if seen is None:
... seen = {}
... sum = 0
... for obj in args:
... if id(obj) not in seen:
... seen[id(obj)] = obj
... sum += sys.getsizeof(obj)
... sum += gettotalsizeof(*gc.get_referents(obj), seen=seen)
... return sum
...
>>> a, b = tee(range(10000))
>>> sum(next(a) for i in range(1000))
499500
>>> gettotalsizeof(a)
750
>>> gettotalsizeof(b)
18734 |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2013年09月19日 11:48:13 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, pitrou |
| 2013年09月19日 11:48:13 | serhiy.storchaka | set | messageid: <1379591293.2.0.269395220303.issue19048@psf.upfronthosting.co.za> |
| 2013年09月19日 11:48:13 | serhiy.storchaka | link | issue19048 messages |
| 2013年09月19日 11:48:13 | serhiy.storchaka | create |
|