从内存中删除数据

时间:2018-03-01 15:55:47

标签: ruby memory memory-management

我有一个脚本本应该获取大JSON文件(100mb)(流过多个部分)并解析它们,我想重复使用脚本而不关闭它,但是在完成数据后它会保留在我的记忆中我无法找到删除它的方法,尝试过:创建一个线程然后将其删除(假设它的局部变量数据将被删除),如下所示,使用全局变量并编辑它们也没有工作,尝试清除名为" get"这里也使用get.clear,

在这个脚本中有一个名为handle的方法,它接收所接收数据的一部分并在新线程中解析它以减少处理时间(每个线程占用一部分数据,所以我们可以说它们是一部分问题是,如果有必要,我不介意分享它的代码

问题是如何从记忆中删除数据?

方面问题:

1)为什么杀死一个线程不会从内存中删除它的数据?

2)为什么在重置变量的值之后,它的数据仍留在我的记忆中?

3)为什么新数据会对旧数据添加(+),即使我为同一个变量设置了一个新值?

抱歉,我试过看看stackoverflow和谷歌,但我似乎无法找到解决方案/答案

    def getinventory(needed)
    $to_kill = Thread.new do
    $items = needed
    $threadnumber = -1
    $itemstoget = []
    $arryofthreads = []
    $parsed = 0
    $found = false
    last_id = 0
    first = true
    loginv("inventory fetch initiated")
    right = false
    until last_id == "end" || $found == true
      if first == "no"
        sleep(0.2)
      end
      right = false
      until right == true
        begin
           get = JSON.parse(RestClient.get("http://steamcommunity.com/inventory/76561198044170935/753/6?start_assetid=#{last_id}&count=5000"))
           right = true
         rescue
           logmain("rescued")
         end
       end
      if first == true
        handle(get.values[0],get.values[1])
        first = false
        if get.keys[3].to_s == "last_assetid"
          last_id = get.values[3].to_s
        else
          last_id = "end"
        end
      elsif first == false
        handle(get.values[0],get.values[1])

        if get.keys[3].to_s == "last_assetid"
          last_id = get.values[3].to_s
        else
          last_id = "end"
        end
      end
    end
    get.clear
    $items = ""
    $threadnumber = -1
    $itemstoget = []
    $arryofthreads = []
    $parsed = 0
    $found = false
  end
end

0 个答案:

没有答案
相关问题