Out of Memory exception

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
YTI
Newbie
Newbie
Posts: 15
Joined: Wed May 24, 2017 12:00 am

Out of Memory exception

Post by YTI » Mon Nov 20, 2017 9:22 am

Hello there,

We are facing a strange issue where our application crashes when running for long hours (Does not occur frequently).
The window running on front contains a Teechart component (TeeChart.WPF.dll v4.1.2010.9282).
Following are the log excerpts from the crash.

------------------------------LOG STARTS---------------------------------------

2017-11-08 20:18:36,460 [-SL] FATAL Engine [(null)] - System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Collections.ArrayList.set_Capacity(Int32 value)
at System.Collections.ArrayList.EnsureCapacity(Int32 min)
at System.Collections.ArrayList.Add(Object value)
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(ChartFont f, Double x, Double y, Int32 angle, String st, TextShape format, Boolean isTitle)
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(ChartFont f, Double x, Double y, Int32 angle, String st, TextShape format)
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(Double x, Double y, Int32 angle, String st, TextShape labelItem)
at Steema.TeeChart.WPF.Axis.AxisDraw.DrawThisLabel(Double labelPos, String tmpSt, TextShape labelItem)
at Steema.TeeChart.WPF.Axis.AxisDraw.DrawCustomLabels()
at Steema.TeeChart.WPF.Axis.AxisDraw.Draw(Boolean calcPosAxis)
at Steema.TeeChart.WPF.Axis.Draw(Boolean calcPosAxis)
at Steema.TeeChart.WPF.Axes.Draw(Graphics3D g)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g, Boolean noTools)
at Steema.TeeChart.WPF.TChart.Draw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.OnRender(DrawingContext drawingContext)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
-----------------------LOG ENDS----------------------------------------------

At this moment, we are clueless about this crash.
Any help would be greatly appreciated.

Best Regards,

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Out of Memory exception

Post by Christopher » Tue Nov 21, 2017 9:35 am

Hello,

Are you adding points into a series over time but not deleting points from that series when they are no longer visible or displayed? This could be the cause of the problem.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

YTI
Newbie
Newbie
Posts: 15
Joined: Wed May 24, 2017 12:00 am

Re: Out of Memory exception

Post by YTI » Wed Nov 22, 2017 8:57 am

Hi Christopher,

Thank you so much for the prompt response.
Are you talking about clearing the Axis label items before adding them?
If yes, we do delete the point's before adding new points.
Please have a look on the below code snippet periodically.

axis.Labels.Items.Clear();
for (decimal i = (decimal)axis.Minimum; i < (decimal)(axis.Maximum + inc); i += (decimal)inc)
{
AxisLabelItem axisLabelItem = new AxisLabelItem(tChart1.Chart);

if ((double)i < axis.Maximum)
{
axisLabelItem.Value = (double)i;
axisLabelItem.Text = DisplayNDecimal((double)i, pds.YAxisDecimalPoint);
}
else
{
axisLabelItem.Value = axis.Maximum;
axisLabelItem.Text = DisplayNDecimal(axis.Maximum, pds.YAxisDecimalPoint);
}
axisLabelItem.Transparent = true;
axisLabelItem.Font.Color = axis.AxisPen.Color;
axisLabelItem.Visible = pds.DataVisibility;
axisLabelItem.Font.Size = this.GraphYAxisLabelFontSize;
axisLabelItem.Font.Name = this.GraphYAxisLabelFontFamily.ToString();
axis.Labels.Items.Add(axisLabelItem);

}


Also we clear all the axis and redraw the axis in case of data update.

if (tChart1.Axes.Custom.Count > 0)
tChart1.Axes.Custom.RemoveAll();

foreach (GraphDataSeries pds in GraphDataSeriesCollection)
{
Steema.TeeChart.WPF.Styles.Line line = tChart1.Series[AxisIndex] as Steema.TeeChart.WPF.Styles.Line;
if (line != null)
{
UpdateSeriesConfiguration(pds, line);
}
Steema.TeeChart.WPF.Styles.Points point = tChart1.Series[AxisIndex] as Steema.TeeChart.WPF.Styles.Points;
if (point != null)
{
UpdateSeriesConfiguration(pds, point);
}
CreateAxis(tChart1[AxisIndex], AxisIndex, pds);
AxisIndex++;
}


Also from the stack trace, it appears like the issue originated from Teechart code, not from user code.
Our client is taking daily reports on this issue progress. Any quick help would be greatly appreciated.

Best regards

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Out of Memory exception

Post by Christopher » Wed Nov 22, 2017 10:00 am

YTI wrote:Thank you so much for the prompt response.
Are you talking about clearing the Axis label items before adding them?
If yes, we do delete the point's before adding new points.
Please have a look on the below code snippet periodically.
Not only that, but the points in the series themselves e.g.

if(tChart1.Series[AxisIndex].Count > 1000)
tChart1.Series[AxisIndex].Delete(0, 500);
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

YTI
Newbie
Newbie
Posts: 15
Joined: Wed May 24, 2017 12:00 am

Re: Out of Memory exception

Post by YTI » Wed Nov 22, 2017 11:08 am

Dear Christopher,

Yes, we are clearing the points in the series also, before adding new points.

private void UpdateGraphData(Dictionary<object, DataItemValue> dataItems)
{
foreach (GraphDataSeries pds in GraphDataSeriesCollection)
{
object ProcessUnitVariableName = pds.PName + "." + pds.UName + "." + pds.VName;
DataItemValue dataItemValue = null;
tChart1.Series.Clear();
}


Any other direction we shall look into ?
Any workaround to fix this?

Best regards,

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Out of Memory exception

Post by Christopher » Wed Nov 22, 2017 11:55 am

YTI wrote: Any other direction we shall look into ?
Any workaround to fix this?
Undoubtedly there is a workaround to fix this, but in order to produce one I will need to reproduce your problem on my machine. Could you please be so kind as to create a Minimal, Complete, and Verifiable example following the instructions here? Once you have created such an example, you could upload it to http://steema.net/upload/ and let me know so I can start work on a solution.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

YTI
Newbie
Newbie
Posts: 15
Joined: Wed May 24, 2017 12:00 am

Re: Out of Memory exception

Post by YTI » Tue Jan 09, 2018 10:30 am

We are not able to mimic the issue in a sample application due to some dependencies. So can i share the code over remote desktop?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Out of Memory exception

Post by Christopher » Tue Jan 09, 2018 11:24 am

YTI wrote:We are not able to mimic the issue in a sample application due to some dependencies. So can i share the code over remote desktop?
I am extremely skeptical of being able to resolve this issue for you over a remote connection.

One further thing you might like to try - download a more recent version of the TeeChart.WPF assembly to see if the problem hasn't already been fixed. You can do this using either:
1) the Pro version, download from https://www.steema.com/downloads/net
2) the Standard version, download from Nuget (inside Visual Studio) or https://www.nuget.org/packages/Steema.T ... .Standard/
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

YTI
Newbie
Newbie
Posts: 15
Joined: Wed May 24, 2017 12:00 am

Re: Out of Memory exception

Post by YTI » Tue Jan 09, 2018 11:25 pm

Our application is still built on .Net 3.5. In this case can we still use the latest version?
Recent trace of the issue is different from earlier. Following is the new trace received from customer,

2017-12-30 18:57:30,033 [-SL] FATAL Engine [(null)] - System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Windows.Media.FormattedText.DrawAndCalculateMetrics(DrawingContext dc, Point drawingOffset, Boolean getBlackBoxMetrics)
at System.Windows.Media.FormattedText.get_Metrics()
at System.Windows.Media.FormattedText.get_WidthIncludingTrailingWhitespace()
at Steema.TeeChart.WPF.Drawing.Graphics3DWPF.MeasureString(ChartFont f, String text)
at Steema.TeeChart.WPF.Drawing.Graphics3D.TextHeight(String text)
at Steema.TeeChart.WPF.Drawing.Graphics3D.get_FontHeight()
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(ChartFont f, Double x, Double y, Int32 angle, String st, TextShape format, Boolean isTitle)
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(ChartFont f, Double x, Double y, Int32 angle, String st, TextShape format)
at Steema.TeeChart.WPF.Axis.DrawAxisLabel(Double x, Double y, Int32 angle, String st, TextShape labelItem)
at Steema.TeeChart.WPF.Axis.AxisDraw.DrawThisLabel(Double labelPos, String tmpSt, TextShape labelItem)
at Steema.TeeChart.WPF.Axis.AxisDraw.DrawCustomLabels()
at Steema.TeeChart.WPF.Axis.AxisDraw.Draw(Boolean calcPosAxis)
at Steema.TeeChart.WPF.Axis.Draw(Boolean calcPosAxis)
at Steema.TeeChart.WPF.Axes.Draw(Graphics3D g)
at Steema.TeeChart.WPF.Chart.InternalDraw(DrawingContext g, Boolean noTools)
at Steema.TeeChart.WPF.TChart.Draw(DrawingContext g)
at Steema.TeeChart.WPF.TChart.OnRender(DrawingContext drawingContext)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

Can you hint when this can happen? Is there anything we can take care in the code?
We never delete a point, we just clear and Add. Following is the flow:
for( index i = 0 ; i < 4;i++)
{
tChart1.Series.Clear();
tChart1.Series.Add( doublevalue1, doublevalue2);
}
This happens for every second as new doublevalue1 and doublevalue2.
Is the above flow OK?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Out of Memory exception

Post by Christopher » Wed Jan 10, 2018 8:18 am

YTI wrote:Our application is still built on .Net 3.5. In this case can we still use the latest version?
yes, the Pro version is still built for .NET 3.5. The Standard version is build in .NET 4.0. I suggest you download the Pro Evaluation version and see if that resolves the problem.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply