5/18/2023 0 Comments .net filewatcher memory leakThe first thing you should do when you encounter the high memory usage is to determine whether the memory of a worker process on an application pool in IIS is leaked or not. When you see the error above, the application pool has already restarted automatically. To recover, the application pool must be restarted, but after doing so, the memory usage again climbs to a high level. It may cause an out-of-memory exception on an application pool in IIS. You consistently see both Process\Private Bytes and Process\Virtual Bytes are increasing or Process\Private Bytes and Process\Working Set of w3wp.exe are increasing and Memory\Available Bytes is decreasing. ProcessĪddressable memory (with a large address-aware process) The following table summarizes the virtual memory which is addressable memory from the web application. When the memory leak in an IIS application pool occurs, increasing physical memory (RAM) does not effective because the memory in this scenario is not the physical memory (RAM) but a virtual memory. However, if you consistently see both Process\Private Bytes and Process\Virtual Bytes are increasing or Process\Private Bytes and Process\Working Set are increasing and Memory\Available Bytes is decreasing, the memory leak will occur and it may cause an out-of-memory exception. It's important to keep in mind that it is normal for high memory allocation as a web application serves requests. This troubleshooter will help you to identify the cause of native memory leak in an IIS application pool. Microsoft makes no warranties, express or implied. This material is provided for informational purposes only. Build() the memory issue goes away.By Apurva Joshi Tools Used in this Troubleshooter: If I remove all the configuration sources by adding the following before. I think I've confirmed it's a memory leak. It probably wont effect me because I don't expect thousands of restarts, but is it worth creating an issue on the github if this is actually a leak? Am I diagnosing this as a memory leak when it isn't? My question is whether this is an issue or not. This is with the GC.Collect and GC.WaitForPendingFinalizers being called at the end of each loop. The application starts at ~10-20mb of memory being used, but after 17000 loops it had gotten up to 200mb . I added WriteLine to track the number of loops that have occured and ran it for a couple minutes. I'm guessing it might be for one of the configuration files? So to me, it seems like there is a file watcher being created at some point in the IHost that isn't properly being disposed. The highlighted items count seems to marry up with the number of looks that have occured. You can see there are a few things that are consistently building up. Var host = Host.CreateDefaultBuilder().Build() Īnd here is the memory snapshot. Private static async Task Main(string args) I can see the GC is being run, so I don't think that it would ever get cleaned up. Below is a simple console app to show pretty much what I'm doing, and you can see it just slowly but consistently gains memory usage. I ended up finding that just starting/stopping a default IHost seemed to cause a similar issue (Though to a lesser degree). That's not terrible, but it made me think I wasn't disposing of something correctly. It seemed like I was gaining 10-50mb for every ~1000 restarts. I found that there was a small memory leak somewhere. Stopping/Starting involves stopping the IHost and disposing of it, then starting a new one. I started doing stress tests on it to see if there was any memory leaks when stopping/starting the 'plugins'. The root app will run as a windows service, and will create an IHost for each 'plugin' so that each one can have its own DI container. I'm currently working on a plugin-like system that requires loading in assemblies at runtime.
0 Comments
Leave a Reply. |