这是否意味着一个对象并不需要手动清除,如果它没有实现IDisposable? [英] Does that mean an object doesn't need to be cleared manually if it doesn't implement IDisposable?

查看:284
本文介绍了这是否意味着一个对象并不需要手动清除,如果它没有实现IDisposable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的问题是以下错误:

The problem I'm facing is the following error:

System.ComponentModel.Win32Exception(0x80004005的):操作成功完成

堆栈跟踪:

at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at MS.Win32.MessageOnlyHwndWrapper..ctor()
at System.Windows.Threading.Dispatcher..ctor()
at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
at System.Windows.Threading.DispatcherObject..ctor()
at System.Windows.Media.Imaging.BitmapDecoder..ctor(SafeMILHandle decoderHandle, BitmapDecoder decoder, Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, Boolean insertInDecoderCache, Boolean isOriginalWritable, Stream uriStream, UnmanagedMemoryStream unmanagedMemoryStream, SafeFileHandle safeFilehandle)
at System.Windows.Media.Imaging.JpegBitmapDecoder..ctor(SafeMILHandle decoderHandle, BitmapDecoder decoder, Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, Boolean insertInDecoderCache, Boolean originalWritable, Stream uriStream, UnmanagedMemoryStream unmanagedMemoryStream, SafeFileHandle safeFilehandle)
at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
at System.Windows.Media.Imaging.BitmapDecoder.Create(Stream bitmapStream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption)
at App.Business.WPFImageService.ReadBitmapFrame(Stream stream)
at App.Business.WPFImageService.UploadFileToAmazon(String amazonPath, Boolean isBlankImage)

通过做一些研究,我发现,当句柄数超过10K的过程中这个问题会发生。而这种情况下,如果我忘了打电话 .Dispose()方法。

By doing some research, I've found that this issue happens when number of Handles exceeds 10k for the process. And this happens if I forgot to call .Dispose() method.

在我的应用程序,我已经清楚地(100%确定)处理每一个对象实现的IDisposable

In my application, I've clearly (100% sure) disposing every single object that implements IDisposable.

虽然我仍面临着这个问题,现在我不知道,每有对象后使用,农具被清除的IDisposable

While I am still facing this issue, now I'm not sure that every object that has to be cleared after usage, implements IDisposable.

我使用下列类型的对象在我的应用程序。

I'm using the following kind of objects in my app.

BitmapFrame DrawingVisual 的DrawingContext RenderTargetBitmap 的SolidColorBrush BitmapDe codeR 的MemoryStream 的FileStream PngBitmapEn codeR

BitmapFrame, DrawingVisual, DrawingContext, RenderTargetBitmap, SolidColorBrush, BitmapDecoder, Stream, MemoryStream, FileStream, PngBitmapEncoder.

的MemoryStream 的FileStream 工具的IDisposable 这我清楚地打电话的Dispose()在他们身上。但是,的DrawingContext 不执行的IDisposable 但是有一个 .Close()方法,该方法也被称为

Stream, MemoryStream and FileStream implements IDisposable which I'm clearly calling Dispose() on them. But, DrawingContext doesn't implement IDisposable however has a .Close() method, which is also being called.

其它对象没有 .Dispose() .Close()同花顺()或任何可以进行相关的话题。

Other objects has no .Dispose(), .Close(), Flush() or anything that can be related to the topic.

我卡住了,为什么我的手柄超过10K(我查过,从任务管理,通过增加手柄柱)。之前,我使用添加WPF / WIC一些图像处理功能,这个应用程序并没有这个问题。

I'm stuck, why my handles are exceeding 10k (I've checked that from task managed, by adding Handle column). This application did not have this issue before I add some image processing functions using WPF/WIC.

任何想法?

推荐答案

尽量确保你也试试using语句来确保你得到的垃圾收集

try to make sure you also try using statement to make sure you get garbage collection

  using (DrawingContext dc = dGroup.Open())

http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext(v=vs.110).aspx

这篇关于这是否意味着一个对象并不需要手动清除,如果它没有实现IDisposable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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