问题描述
我正在用 Merb 开发网络应用程序,我正在寻找一些安全稳定的图像处理库.我曾经在 php 中使用 Imagick,然后转移到 ruby 并开始使用 RMagick.但有一个问题.长时间运行的脚本导致内存泄漏.有几个解决方案存在,但我不知道哪个是最稳定的.那么,你怎么看?
Im developing web-application with Merb and im looking for some safe and stable image processing library. I used to work with Imagick in php, then moved to ruby and start using RMagick. But there is a problem. Long running scripts causing memory leaks. There are couple solution exists, but I don't know which one is the most stable. So, what do you think?
现在,我的应用程序使用我编写的内部 API 来处理图像,在 PHP 中.它与其他应用程序一起在单独的服务器上运行,所以这不是一个大问题.但我认为它不是一个好的架构.
Right now, my app uses internal API that i wrote to process images, in PHP. Its running on separate server along with other applications, so its not a big problem. But i think its not a good architecture.
无论如何,我会考虑任何实用技巧.
Anyway, i`ll consider any practical tips.
推荐答案
我也遇到过这个问题 - 解决方案是强制垃圾回收.
I too have encountered this issue - the solution is to force garbage collection.
当您将图像变量重新分配给新图像时,只需使用 GC.start 以确保从内存中释放旧引用.
When you have reassigned the image variable to a new image simply use GC.start to ensure the old reference is released from memory.
在RMagick以后的版本上,我也相信你也可以调用destroy!完成处理后在图像上.
On later versions of RMagick, I also believe you can also call destroy! on the image when you have finished processing it.
两者的结合可能会确保您被覆盖,但我不确定对性能的现实生活影响(我认为在大多数情况下可以忽略不计).
A combination of the two would probably ensure you are covered, but im not sure of the real life impact on performance (I would assume it is negligible i most cases).
或者,您可以使用 mini-magick,它是 ImageMagick 命令行客户端的包装器.
Alternatively, you could use mini-magick which is a wrapper for the ImageMagick commandline client.
这篇关于如何在 Ruby 中处理 RMagick 中的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!