Antoine Pitrou added the comment: > getsizeof() is interesting only if it gives sensible results when used > correctly, especially if you want to sum these values and get a global > memory usage.
"Getting a global memory usage" isn't a correct use of getsizeof(), though, because it totally ignores the memory allocation overhead (not to mention fragmentation, or any memory areas that may have been allocated without being accounted for by __sizeof__). If you want global Python memory usage, use sys._debugmallocstats(), not sys.getsizeof(). > One usage is to traverse objects through gc.get_referents(); in this > case the definition above is correct. What are the intended semantics? get_referents() can give you references you didn't expect, such as type objects, module objects... > Now, are you suggesting to traverse objects differently? With dir(), > or __dict__? sys.getsizeof() gives you the memory usage of a given Python object, it doesn't guarantee that "traversing objects" will give you the right answer for any question. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19048> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com