When I debug .net code, how can I know when the garbage collector runs?
I do not wish to control when the garbage collector runs. I only wish to be able to know when it is running. I have some code that is running out of resources. I know that the resources are not being used; I want to know when the GC is running to free them.
Oh, and the resources I have in mind are connections from a Sql connection pool, not memory :-)
Garbage collection occurs when one of the following conditions is true: The system has low physical memory. The memory that is used by allocated objects on the managed heap surpasses an acceptable threshold. This threshold is continuously adjusted as the process runs.
NET's garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap.
When the JVM doesn't have necessary memory space to run, the garbage collector will run and delete unnecessary objects to free up memory. Unnecessary objects are the objects which have no other references (address) pointing to them.
When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.
garbage collection does not free up your pooled database connections. connections are returned to the pool when you close/dispose the connection object. the connection pool itself manages when it needs to open more connections and close them again based on how hard you are hitting your pool and your configuration of the pool in the connection string. garbage collection is not related to this in any way other than reclaiming the memory allocated to instances of SqlConnection. you are barking up the wrong tree in asking about garbage collection and getting (and accepted) answers that don't have anything to do with what you are after (if i understand your question correctly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With