Chris MC
Chris MC

Reputation: 113

C# Handles Count

I was looking into the possibility that one of my applications might have a memory leak, so started playing about with some very basic code samples. One I ended up with, when left over time, started to increase greatly in terms of the number of Handles (>3000). It is a very simple Console application with the code as follows:

public static void Main(string[] args)
{
    using (SqlConnection sqlConnection = new SqlConnection())
    {
    }

    Console.ReadLine();
}

Taking out the SqlConnection call removes any Handle increase, so I am assuming it has something to do with the connection pool. But as this only runs once before basically going into a wait for input, why would the Handle count keep increasing?

Thanks.

Upvotes: 6

Views: 2414

Answers (2)

tia
tia

Reputation: 9718

If you are running it on .NET 4.0, this might be the case

https://connect.microsoft.com/VisualStudio/feedback/details/691725/sqlconnection-handle-leak-net-4-0

Upvotes: 4

MikeT
MikeT

Reputation: 5500

you will find that the majority of the object cache is composed of framework objects such as those created so you can access the config files and resources with out having to manually parse the files yourself

IIRC the default object cache is about 4000 objects.

you have to remember that just because your only creating and disposing of a single object doesn't mean that's all the frame work is doing

Upvotes: 0

Related Questions