gpt4 book ai didi

python - 垃圾收集 python rss 内存

转载 作者:太空宇宙 更新时间:2023-11-04 05:59:29 25 4
gpt4 key购买 nike

我正在分析我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com