Handle increase - TChart in new thread

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
SurveyBob
Newbie
Newbie
Posts: 22
Joined: Mon Dec 14, 2009 12:00 am

Handle increase - TChart in new thread

Post by SurveyBob » Thu Mar 18, 2010 2:21 pm

Hi,
I want to create charts which shall be stored in a database. So the charts are not shown in a UI or something.
The chart is periodically created after a specific time span. Responsible for the chart creation is a new thread which runs in the background.
The problem I noticed is that the handle count increases even though I call Dispose() on the chart object.

Code: Select all

public void test()
		{
			for ( int i = 0; i < Int32.MaxValue; i++ )
			{
				Thread thread = new Thread( new ThreadStart( delegate()
				{
					// Lock the image creation because TeeChart seems to use GDI functions
					// (in the ContourMapControls constructor) which are not thread-safe.
					test();
				} ) );

				thread.Name = "Handle increase demo";
				thread.Priority = ThreadPriority.BelowNormal;
				thread.Start();
			}
		}

		private void test1()
		{
			TChart tchart = new TChart();

			try
			{
			}
			finally
			{
				tchart.Dispose();
			}

			Thread.Sleep( 10 );
		}
The application runs on a server system which means we cannot just shut down and start the application again.
Do I use something wrong or is there a alternative?

I also attached a sample project.

Thanks.

SurveyBob
Attachments
TChart_HandleIncrease.zip
Sample Project
(26.15 KiB) Downloaded 437 times

SurveyBob
Newbie
Newbie
Posts: 22
Joined: Mon Dec 14, 2009 12:00 am

Re: Handle increase - TChart in new thread

Post by SurveyBob » Thu Mar 18, 2010 2:28 pm

Sorry, take this sample project.
Attachments
TChart_HandleIncrease.zip
(26.19 KiB) Downloaded 425 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Handle increase - TChart in new thread

Post by Narcís » Fri Mar 19, 2010 4:04 pm

Hi SurveyBob,

As you have already noticed, TeeChart is not thread-safe. Have you tried doing something similar without using threads? Do you get the same behavior?

Also, how do you know handle count is increasing?

Please notice that Dispose doesn't free objects immediately, it's garbage collector who does that task in the .NE Framework. Therefore, deterministic finalization is not available in .NET Framework as it's explained here:

http://www.geekinterview.com/question_details/5532
http://stackoverflow.com/questions/1884 ... ation-in-c
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

SurveyBob
Newbie
Newbie
Posts: 22
Joined: Mon Dec 14, 2009 12:00 am

Re: Handle increase - TChart in new thread

Post by SurveyBob » Fri Mar 19, 2010 4:32 pm

Hi Narcis,

yes, I did the same without using a separate thread and the handle count did not increase. However, the handle count also increases using a simple .NET Control object instead of a TChart object. So this is a general problem because a Control object could be everything such as a button or a drop-down box.

I am aware of the garbage collections behavior but I ran several tests with a duration of at least 14 hours and the handle count did not decrease a single time during the test.
You can see the handle count when you open the Task Manager ("Process" tab). Under the "View" menu entry, you can choose "Select Columns..." to insert the handle column. Afterwards you start the application which you'll then find in the list under the "Process" tab.

I have an idea why the handle count increases but nothing specific yet and since this is not just a TChart issue I keep on investigating on my own. Maybe I find a solution for that.

Thanks for your help.

SurveyBob

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Handle increase - TChart in new thread

Post by Narcís » Fri Mar 19, 2010 4:42 pm

Hi SurveyBob,

Thanks for your feedback.
I have an idea why the handle count increases but nothing specific yet and since this is not just a TChart issue I keep on investigating on my own. Maybe I find a solution for that.
Probably the handle count increases during application's execution but it may get a point when it becomes stable as new objects are created and destroyed at a similar pace.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply