在 RAM 密集型程序上过早 ruby 退出

Premature ruby exit on RAM intensive program

我正在尝试让我的 Ruby 文件打印所有可能存在的 IP。

但是,它提前退出并且没有错误。

require 'ipaddress' #Is Installed

RUBY_GC_HEAP_GROWTH_FACTOR = 0.1 
#Changes How Much RAM Is Taken Every Request (Tested And Removed, Not The Problem)

#Exits After Here

ip = IPAddress "0.0.0.0/24" #First Range
ip.to('255.255.255.255') #End Range

#Exits Before This Point

out_file = File.new("out.txt", "w") #Create & OpenFile
out_file.puts("#{ip}") #Output Variable To File
out_file.close #Save And Exit
sleep(8)

RAM 不是问题,因为它有 8Gb 的价值,并且代码在达到我的 RAM 限制之前退出。

什么导致程序关闭?

我认为您的方向是正确的,但您应该以稍微不同的方式使用 gem:

ip = IPAddress "0.0.0.0/0"

File.open("out.txt", "w") do |file|
  ip.each do |ip_address|
    file.puts ip_address
  end
end

sleep(8)

当我测试它时,它在我的笔记本电脑上使用了有限(合理)的 RAM。但是,我没有写到文件,只是写到控制台。希望您准备好处理这将产生的文件大小。