Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS application pool and .NET garbage collection

Consider an ASP.NET application with has a connection pool memory leak problem (where connections are not being closed correctly for example).

Does recycling the application pool clear the connection pool (thus allowing more connections to be made)?

If the connections are left in memory until the Garbage Collector removes them, does this happen when the application pool is restarted (or are/can they left beyond that)? I also understand the Garbage Collector could clean them up at anytime as well, but are they still in use and unable to be collected until a reset or application pool restart?

I'm reviewing a system where the end goal is obviously to have the code corrected to manage the connections correctly, and I'm trying to gain more of an understanding about the garbage collection/application pool process.

like image 581
davidsleeps Avatar asked Jul 20 '09 06:07

davidsleeps


People also ask

Does .NET have a garbage collector?

. 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.

What is IIS garbage collection?

In the common language runtime (CLR), the garbage collector (GC) serves as an automatic memory manager. The garbage collector manages the allocation and release of memory for an application. For developers working with managed code, this means that you don't have to write code to perform memory management tasks.

What causes IIS app pool to recycle?

Application pool(s) recycle. The worker process hosting your applications can recycle due to a configuration change, time limit, idle timeout, excessive memory usage, and many other reasons. Application restart(s).


1 Answers

Yes, recycling the app pool kills and restarts the IIS process responsible for running your application. All resources are freed at this point, simply because the process is exiting.

If the process is never restarted and simply leaks handles, the garbage collector will eventually clean them up. However, it's likely that you'll run out of handles for whatever resource is leaking before this happens. This is why it's important to call Dispose() on these objects(preferably by the "using" pattern) so that the resources are freed as soon as the app is done with them and not when the garbage collector gets around to it.

like image 113
Jesse Weigert Avatar answered Sep 26 '22 02:09

Jesse Weigert