|
System.OutOfMemoryException error |
Posted by chang on May-26-2015 16:37 |
|
Hi Peter
I am writing in MS C#. I have a finance chart and I keep getting an unhandled System.OutOfMemoryException when I mouse over the WinChartViewer and the application freezes. I have a callback for winChartViewer1_MouseMove but it has a couple of Debug.WriteLine statements and nothing else and I also have the entire method in a try catch block. I am currently using the chartdirector 5.1 version so it's fully managed. My .Net Framework version 3.5 is also managed and I didn't have that many programs running at that point in time. Can it be an unhandled exception in the Chartdirector library even before the delegation reach my callback? Below is the error message, please advise thanks:
System.OutOfMemoryException was unhandled
Message="Exception of type 'System.OutOfMemoryException' was thrown."
Source="mscorlib"
StackTrace:
at System.IO.MemoryStream..ctor(Int32 capacity)
at ChartDirector.DrawArea.outImage()
at ChartDirector.BaseChart.makeImage()
at ChartDirector.WinChartViewer.g()
at ChartDirector.WinChartViewer.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(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)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FChart.Form1.Main() in C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2008\\Projects\\RaidersProduction\\FChart\\Form1.cs:line 2993
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() |
Re: System.OutOfMemoryException error |
Posted by Peter Kwan on May-27-2015 01:02 |
|
Hi chang,
Are you using track cursor? If this is the case, there should be a line in your code that calls
"viewer.updateDisplay();" in the MouseMovePlotArea event handler to update the track
cursor when the mouse moves. For testing, please try to add the following line after
viewer.updateDisplay:
System.GC.Collect();
When "viewer.updateDisplay();" is called, ChartDirector needs to allocate memory to create
the new image, and release the memory of the old image. So overall, there should be no net
memory usage. However, in .NET, the system reclaims memory by "garbage collection". The
garbage collector is non-deterministic and it is not sure when it will reclaim the memory. I
have seen a few cases in which the "garbage collector" does not reclaim memory timely
enough that the .NET system runs of out memory, even when a lot of memory are unused.
If this is the cause of the problem, forcing the garbage collector to run using
System.GC.Collect(); should solve the problem.
If the above does solve the problem, you can try to modify the code to run
System.GC.Collect(); only once every 10 or 20 mouse move events to reduce the garbage
collection overhead. (You can keep a counter to count how many times the mouse move
events have occured.)
Regards
Peter Kwan |
Re: System.OutOfMemoryException error |
Posted by chang on May-27-2015 11:11 |
|
Sounds just about right. I shall test and revert if problems still exists after modifications. Thank you very much! |
|