We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

ObjectDisposedException from model reporting changes to a disposed chart''s series

I''m having trouble with ObjectDisposedException referring to a disposed chart. Here''s what I''m doing: 1. I create a model that implements IChartSeriesModel. It has a thread that makes changes every so often and reports them via its Changed event. 2. I create a chart. 3. I create a new series based on the model, and add the series to the chart. I no longer hold onto a reference to the series or the model. 4. The chart displays just fine, and refreshes nicely as the data changes. 5. When I''m done with the chart, I get rid of the form containing it. It goes away. 6. Visual Studio then reports: An unhandled exception of type ''System.ObjectDisposedException'' occurred in Unknown Module. Additional information: Cannot access a disposed object named "LineChart". The problem appears to be that the model is still around and still reporting changes to its subscribers, and that the disposed chart still holds a series that is still a subscriber to the model''s change event. I''ve worked around it by overriding Dispose in my subclass of ChartControl and calling Series.Clear there. If that''s the right answer -- which I somehow doubt -- it seems like it should be happening in ChartControl.Dispose. If it''s the wrong answer, what *should* be happening instead? What is the intended lifecycle for a series and model? Offhand, it seems like when a chart is disposed it should dispose each of its series, and that the dispose for a series should unregister it from its model. But that''s without having thought through it too carefully. Any suggestions? Thanks!

9 Replies

DJ Davis Jebaraj Syncfusion Team October 1, 2004 07:55 PM UTC

Hi Rich, Thank you for bringing this issue to our attention. We regret for the inconvenience caused. The ChartControl''s Dispose method can be modified to clear the series collection. We think the actual problem lies with incorrect reference counting for events subscribed to by the Model and the ChartControl with the series objects. Our development team is working on resolving these issues and they should be fixed in the next possible build. Thank you for your patience. Regards, Davis


AD Administrator Syncfusion Team October 12, 2004 04:07 PM UTC

Now that we''re clearing the series from within our Dispose, we run into other problems: the control wants to react to its series change by adjusting its axes. When we close our test application with a chart visible, it reports: An unhandled exception of type ''System.Runtime.InteropServices.ExternalException'' occurred in system.drawing.dll Additional information: Internal error: GDI+ is not properly initialized. And here''s the stack: System.Drawing.Graphics.FromHwndInternal(3868752) System.Windows.Forms.Control.CreateGraphicsInternal() System.Windows.Forms.Control.CreateGraphics() Syncfusion.Windows.Forms.Chart.ChartControl.CalculateLabelSizes() Syncfusion.Windows.Forms.Chart.ChartControl.axis_DimensionsChanged({Syncfusion.Windows.Forms.Chart.ChartAxis}, {System.EventArgs}) Syncfusion.Windows.Forms.Chart.ChartAxis.OnDimensionsChanged({System.EventArgs}) Syncfusion.Windows.Forms.Chart.ChartAxis.SetRange({Syncfusion.Windows.Forms.Chart.MinMaxInfo}) Syncfusion.Windows.Forms.Chart.ChartControl.SeriesChanged({Syncfusion.Windows.Forms.Chart.ChartSeriesCollection}, {Syncfusion.Windows.Forms.Chart.ChartSeriesCollectionChangedEventArgs}) Syncfusion.Windows.Forms.Chart.ChartSeriesCollection.OnClearComplete() System.Collections.CollectionBase.Clear() MyXYChart.ClearSeries() Line 575 C# MyXYChart.Dispose(false) Line 748 C# System.ComponentModel.Component.Finalize() Any suggestions? Thanks!


AD Administrator Syncfusion Team October 12, 2004 06:04 PM UTC

One more thing: as a further workaround, it looks like I can prevent this new exception by calling BeginUpdate before ClearSeries in my chart subclass''s Dispose method. That may prevent the axis adjustments happening in response to the series deletion during disposal. But obviously things are getting uglier as we go. Any thoughts? Thanks! - Rich


DJ Davis Jebaraj Syncfusion Team October 22, 2004 05:25 PM UTC

Hi Rich, Sorry about the delay in responding. We will change the behavior so that the axes are not reinitialized when the chart is disposed. This should take care of the problems you are experiencing. Thank you for your patience. Regards, Davis


JL Jarrod Lloyd September 23, 2005 05:46 AM UTC

Did this problem ever get resolved? I am having the same problem still! >Hi Rich, > >Sorry about the delay in responding. > >We will change the behavior so that the axes are not reinitialized when the chart is disposed. This should take care of the problems you are experiencing. > >Thank you for your patience. > >Regards, > >Davis


RS Rich Strangfeld October 4, 2005 04:05 PM UTC

I don''t think so. It still crops up from time to time. - Rich >Did this problem ever get resolved? > >I am having the same problem still!


DJ Davis Jebaraj Syncfusion Team October 4, 2005 10:47 PM UTC

Hi Jarrod / Rich, I have increased the priority for this issue again. The development team had already addressed it once before, but I am asking to look into it again. I regret for the delay and the inconvenience caused. Thank you for your patience. Regards, Davis


JL Jarrod Lloyd October 18, 2005 10:19 PM UTC

Any update on this problem?


JL Jarrod Lloyd October 18, 2005 10:22 PM UTC

Rich, Is it possible to see the code you wrote to workaround this problem? Thanks

Loader.
Live Chat Icon For mobile
Up arrow icon