我想知道我的Python应用程序的内存使用情况,并且特别想知道哪些代码块/部分或对象占用了大部分内存.Google搜索显示商业广告是Python Memory Validator(仅限Windows).
我没有尝试任何人,所以我想知道哪一个是最好的考虑:
提供大部分细节.
我必须对代码进行最少或不做任何更改.
有没有办法让Python程序确定它当前使用了多少内存?我已经看过有关单个对象的内存使用情况的讨论,但我需要的是进程的总内存使用量,以便我可以确定何时需要开始丢弃缓存数据.
我最近对算法感兴趣,并开始通过编写一个简单的实现,然后以各种方式优化它来探索它们.
我已经熟悉用于分析运行时的标准Python模块(对于大多数事情我已经发现IPython中的timeit魔术功能已足够),但我也对内存使用感兴趣,所以我也可以探索这些权衡(例如,缓存先前计算的值表的成本与根据需要重新计算它们的成本.是否有一个模块可以为我分析给定函数的内存使用情况?
How efficient is python (cpython I guess) when allocating resources for a newly created instance of a class? I have a situation where I will need to instantiate a node class millions of times to make a tree structure. Each of the node objects should be lightweight, just containing a few numbers and references to parent and child nodes.
For example, will python need to allocate memory for all the "double underscore" properties of each instantiated object (e.g. the docstrings, …