【问题标题】:Memory doesn't release内存不释放
【发布时间】:2017-06-29 05:02:43
【问题描述】:

我有一个创建应用程序备份并将其下载到 zip 文件中的功能,其中包含数据库、图像、文件等中的数据。为此,我创建了一个大的临时文件(使用 Tempfile 类)使用 send_data 发送到浏览器,但是当我在 send_data 后删除它时,下载失败并且它的内存没有被释放。

send_file(zip_data.path, type: 'application/zip', filename: "#{model_name}.zip")

zip_data.unlink

服务类:http://pastebin.com/MskjP8d7

控制器方法:http://pastebin.com/CV9Wr27h

【问题讨论】:

    标签: ruby-on-rails ruby sendfile x-sendfile


    【解决方案1】:

    这是因为在执行unlink 方法时,请求还没有被完全处理,服务器还没有真正发送文件。 send_file 实际上是由 Web 服务器处理的。

    您可以放弃unlink 电话。 Ruby garbage collector will clean up Tempfiles once they are out of scope。或者,将 send_file 替换为 send_data,然后从控制器中手动发送 Zip 文件的二进制内容。

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2016-09-14
      • 2015-08-19
      • 2012-05-15
      • 2018-01-26
      • 2011-09-30
      • 2012-03-18
      • 2011-08-10
      • 2020-09-17
      相关资源
      最近更新 更多