gpt4 book ai didi

ruby - 尽管将历史大小设置为 0 并清除历史记录,但 Mechanize 内存泄漏

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:35 25 4
gpt4 key购买 nike

这是重现问题的示例脚本

require 'mechanize'

agent = Mechanize.new
agent.history.max_size = 0

5000.times do |i|
agent.get('http://www.yahoo.com')
agent.history.clear

p `ps -o rss -p #{$$}`.strip.split.last.to_i * 1024 # Prints out memory usage of the ruby process
end

我正在执行 agent.history.max_sizeagent.history.clear 但似乎内存使用量随着每个循环而增加。

这是显示内存使用量增加的输出(从 48MB 开始,每次循环增加 1-2MB)。

48603136
50274304
51470336
53260288
54984704
55836672
56799232
57884672
59150336
60358656
61349888
62193664
...

如何让 Mechanize 停止泄漏内存?

最佳答案

那不是内存泄漏,只是有些东西还没有被 gc 处理过。放:

GC.start

如果您觉得需要它,请在循环中,否则忽略它可能是安全的。

关于ruby - 尽管将历史大小设置为 0 并清除历史记录,但 Mechanize 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26754110/

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