Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does that mean an object doesn't need to be cleared manually if it doesn't implement IDisposable?

The problem I'm facing is the following error:

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully

Stack trace:

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)

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.

In my application, I've clearly (100% sure) disposing every single object that implements 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, BitmapDecoder, Stream, MemoryStream, FileStream, PngBitmapEncoder.

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.

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

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.

Any ideas?

like image 271
user3332579 Avatar asked Mar 03 '14 17:03

user3332579


1 Answers

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

like image 66
COLD TOLD Avatar answered Sep 30 '22 19:09

COLD TOLD