Hi Krushik,
From your error message, it looks like it is ChartDirector 5.x or an earlier version of ChartDirector.
There are many reasons why there can be out of memory exceptions. One possible reason is the chart created is exceptionally large, such as 50000 x 50000 pixels, or the code is trying to use a background image that large, etc., and the machine may not have sufficient memory to support them. The exceedingly large size may be unintentional. For example, I have encountered a case where the user is setting the chart size based on the windows size. However, in his framework, the window size can become an unexpected value when the window is minimized, and this cause the chart size to be unexpected and trigger this kind of problem.
Another possibility is that the .NET system may not perform garbage collecton to free memory in time if many charts are created and then removed. This occurs mostly when the chart is large and updated very fast, such as when there are track cursors or drag to scroll. The charts are computer graphics, and it needs large blocks of memory. When a new chart is created, the previous chart is discarded. However, .NET will not reclaim the memory until garbage collection time, and it is possible for the .NET system to run out of memory even if there should be a lot of memory available. To solve the sort of problem, there are two methods:
(a) Add code to ask .NET to perform garbage collection (instead of letting .NET automatically determine when to perform garbage collection):
System.GC.Collect();
You may run the above code every 10 charts created (or even every chart created to avoid running out of memory even if there are a lot of memory).
(b) You may upgrade to ChartDirector 6. In ChartDirector 6, we have added special code to work around these garbage collection issues by managing the memory ourselves.
Regards
Peter Kwan |