python - 垃圾收集 python rss 内存

标签 python memory memory-leaks rss

我正在分析我的 Python 程序,我想知道它使用了多少内存,如果有任何方法可以清除它,我注意到它使用了大量的 rss 内存,这是我进行分析的方式这是:

p = psutil.Process(os.getpid())
print p.get_memory_info()

我注意到在我调用了几个函数后使用的 rss 内存急剧增加,我想在完成后删除这些变量。我该怎么做才能清除 rss 内存?但如果我这样做:

p = psutil.Process(os.getpid())
print p.get_memory_info()
ll = []
ll.append(ll)
print p.get_memory_info()

rss 中没有分配内存。

RSS 中到底放了什么?我有什么办法可以清除它?这样做安全吗?

最佳答案

根据 psutil docs , rss 根据您的操作系统引用不同的值:

Return a tuple representing RSS (Resident Set Size) and VMS (Virtual Memory Size) in bytes. On UNIX rss and vms are the same values shown by ps. On Windows rss and vms refer to “Mem Usage” and “VM Size” columns of taskmgr.exe.

假设您使用的是 Linux,RSS(来自 What you can find out about the memory usage of your Linux programs):

a process's RSS is just how many page table entries in its virtual memory areas point to real RAM (...) Your process's RSS increases every time it looks at a new piece of memory (and thereby establishes a page table entry for it).

您可以检测 Python 解释器来运行 garbage collection .

检查 this SO post answers还有这个FAQ entry了解更多详情。

关于python - 垃圾收集 python rss 内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25900087/

相关文章:

c# - 固定和不安全有什么区别

c# - 以编程方式查找对象使用的内存

file - 如何在 Linux 中查找哪个进程正在泄漏文件句柄?

java - java中的垃圾收集是特定于某个JVM的,如果一个JVM中的应用程序发生内存泄漏,其他JVM会发生什么情况

c++ - 查找数组之间的内存泄漏

python - 当另一个进程仍在写入时删除文件

python - Django TypeError <Page 1 of 8> 不是 JSON 可序列化的

具有很少非零(非常稀疏)的 Python 洗牌数组

Python:用变量替换完全匹配的子字符串

ios - ios objective c中的内存管理