如何在Ruby中处理RMagick中的内存泄漏? [英] How to deal with memory leaks in RMagick in Ruby?

查看:83
本文介绍了如何在Ruby中处理RMagick中的内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Merb开发Web应用程序,并正在寻找一些安全稳定的图像处理库.我曾经在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?

现在,我的应用使用PHP编写的内部API处理图像.它与其他应用程序一起在单独的服务器上运行,因此它不是一个大问题.但是我认为它不是一个好的架构.

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中的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆