在Zxing的System.Drawing.Bitmap可能的内存泄漏 [英] Possible memory leak in Zxing's System.Drawing.Bitmap

查看:1103
本文介绍了在Zxing的System.Drawing.Bitmap可能的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用MonoTouch的工作。我有打开相机,然后需要处理当前正在拍摄的图像的应用程序。我使用的代码,这是非常相似的的https:/ /github.com/reinforce-lab/com.ReinforceLab.MonoTouch.Controls/tree/master/VideoCaptureSample/



我的代码和利率之间的差异他们是在其中放置在我的UIImagePickerController OverlayView.cs不过,我有以下代码:使用(VAR screenImage

  = CGImage.ScreenImage.WithImageInRect(帧))
{
_imageView = UIImage.FromImage(screenImage);
位图srcbitmap =新System.Drawing.Bitmap(_imageView);
}



但是这段代码运行会导致内存中,直到应用程序关闭,不断填满。它仿佛在System.Drawing.Bitmap永远不会处理。我使用ZXing.monotouch所以我需要的位图,这样我可以创建位图的字节[]传递到RGBLuminanceSource



这是我如何能得到任何想法这很好地发挥?


解决方案

如果您使用的代码[1]那么它看起来相当不完整的。没有释放从AllocHGlobal分配的内存,这将导致内存不足的条件。



这是不是一个MonoTouch的错误 - 斑马线代码应在Bitmap类实现IDisposable,确保处置时,一切都被释放(或当GC运行其终结器)<。 / p>

您既可以完成类(即实现IDisposable)或复制/粘贴,为您提供包含图像一个byte []缓冲区的一部分(释放非托管内存中一旦它复制到管理缓冲区)。



[1]的 https://github.com/JohnACarruthers/zxing.MonoTouch/blob/master/Bitmap.cs


I am currently working with Monotouch. I have an application which opens the camera and then needs to process the image that is currently being captured. I am using code which is very similar to https://github.com/reinforce-lab/com.ReinforceLab.MonoTouch.Controls/tree/master/VideoCaptureSample/

The difference of interest between my code and theirs is that in OverlayView.cs which is placed over my UIImagePickerController however, I have the following code:

using (var screenImage = CGImage.ScreenImage.WithImageInRect(Frame))
{
    _imageView = UIImage.FromImage(screenImage);
    Bitmap srcbitmap = new System.Drawing.Bitmap(_imageView);
}

However running this code will cause memory to continuously fill up until the application closes. It seems as though the System.Drawing.Bitmap is never disposed of. I am using ZXing.monotouch so I need the bitmap so that I can create a bytes[] of the bitmap to pass into an RGBLuminanceSource

Any ideas on how I can get this to play nicely?

解决方案

If you're using the code from [1] then it looks rather incomplete. Nothing frees the memory allocated from AllocHGlobal, which would lead to out-of-memory condition.

This is not a MonoTouch bug - the zxing code should implement IDisposable on the Bitmap class and ensure everything gets freed when disposed (or when the GC runs its finalizer).

You can either complete the class (i.e. implement IDisposable) or copy/paste the part that provides you a byte[] buffer containing the image (and free the unmanaged memory once it's copied into the managed buffer).

[1] https://github.com/JohnACarruthers/zxing.MonoTouch/blob/master/Bitmap.cs

这篇关于在Zxing的System.Drawing.Bitmap可能的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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