Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
Hi,

Am getting strange issue in window 8. My application is working fine on other OS (Win 7 and XP). I checked in task manager and compared my application memory both in Win7 and Win8. i found out that in window 8 my application Handlers get above 7000 and i get "out of memory exception" while in window 7 handlers never exceed 500. Why is this ? and how can i fix this issue in window 8? kindly help

Error Message: 
Out of memory.
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at System.Drawing.Image.FromStream(Stream stream)
   at Infragistics.Win.Misc.SplitterButtonUIElement.GetDefaultButtonImage()
   at Infragistics.Win.Misc.SplitterButtonUIElement.DrawImage(UIElementDrawParams& drawParams)
   at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams)
   at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams)
   at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams)
   at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams)
   at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams)
   at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics)
   at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics)
   at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics)
   at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize)
   at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
   at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Posted
Updated 25-Mar-14 21:35pm
v3
Comments
Sergey Alexandrovich Kryukov 26-Mar-14 3:19am    
Different versions of the OS utilize memory differently. So, why are you so surprised? How can you expect any help if we don't even know what are those handlers and why do you need so many?
—SA
Waqas Ahmad Abbasi 26-Mar-14 3:22am    
These handlers are not getting dispose in window 8, as I mentioned in windows 7 and XP these handlers never exceeds 500
Sergey Alexandrovich Kryukov 26-Mar-14 3:25am    
"Handlers" is a very broad term. You need to describe exactly what are they. You could have memory leak which is manifested differently (yes, memory leaks are quite possible with .NET, especially of you purely understand how memory works)...

Look, what are you talking about? No code samples, no explanations, nothing? Still hoping for some help, really? :-)

—SA
Waqas Ahmad Abbasi 26-Mar-14 3:26am    
let me post exception here.
Sergey Alexandrovich Kryukov 26-Mar-14 3:28am    
I'm afraid exception information without code sample is also not informative...
You need to try to model the situation with extremely simplified code sample.
—SA

1 solution

I said that showing exception stack along would be not informative, but actually, after looking at it I got a clear idea what, most likely, is missing. Thank you.

Please look thoroughly at the declaration of the class System.Drawing.Image:
http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx[^].

Please, pay special attention for this: it implements the interface System.IDisposable:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^].

It means that you need to guarantee that IDisposable.Dispose() is always called before you loose the access to each and every instance of the image. Garbage Collector cannot completely dispose the object of the types implementing this interface. Most typical reason is that such object use unmanaged resources. Roughly speaking, your unmanaged resources you use leaks out.

This is not the only possible reason for memory leaks. I suspected your images due to the fact that you reported that handles are collected. This is quite a syndrome.

There are other possible reasons for memory leaks. First of all, please read on the principles of Garbage Collection: http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[^].

I explained how, despite of the automated garbage collection, you still could allow some leaks, in my past answers:
Best way to get rid of a public static List Causing an Out of Memory[^],
Memory management in MDI forms[^],
Memory leak in WPF DataBinding[^],
deferring varirable inside the loop can cuase memory leak?[^],
Garbage collectotion takes care of all the memory management[^].

—SA
 
Share this answer
 
Comments
CPallini 26-Mar-14 4:10am    
My 5.
Sergey Alexandrovich Kryukov 26-Mar-14 11:07am    
Thank you, Carlo.
—SA
Waqas Ahmad Abbasi 27-Mar-14 2:51am    
I have checked and make sure dispose is being called. As I mentioned its working fine in window 7, When I close forms, memory is getting clear. Problems come in window8. Am using same code on window 8 but memory is not getting clear and handles keep on increasing until exception occurs.
Sergey Alexandrovich Kryukov 27-Mar-14 3:06am    
I paid attention for that in the very beginning and it looked somewhat puzzling. At the same time, I thought that you had some memory leaks on both platforms, because you collected some 500 handles in minimal case. Why would you need so many handles at the same time? So, I though you did not want to collect them, but they were collected due to some leak. The different between platform could be attributed to one or another reason, even timing differences.

Even now, I am not sure you really disposed everything. There is a simple way to check it up (simple if your code is accurately written). You can implement IDisposable.Dispose and constructor in derived class(es), to count the balance between creations and disposals. But you could have different kinds of memory leaks.

Besides, your available memory could be different...

—SA
Waqas Ahmad Abbasi 27-Mar-14 5:28am    
i found out some more details. in early 2013 there was Window 7 update KB2670838. which was causing same issue back than in our software am facing in window 8 right now. uninstalling that update fixed it in window 7. I checked in window 8 there is no such update available/installed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900