Simple ways to Improve and reduce Memory Allocation in C#
C# is a managed memory language, that means you don’t need care about memory usage, disposing objects and that stuff, because there is a dude named Garbage Collector, which care about our objects and discard them when is needed, generally. But that is a tricky behavior. Eventually, We need handle with database connections, files, integrate our systems with some devices through drivers etc. And that is the problem, almost all these features is not Garbage Collection concern.
That is called unmanaged resources, that means Garbage Collector doesn’t clean up those features from memory. We need to dispose all the things when doesn’t use it anymore. If you haven’t heard much about GC, take a look at Microsoft’s documentation.
When We talking about resources consumption, generally, everybody I had met didn’t care about it. In most cases, We pay attention in resources usage when its too late, when the server is freeze and the applications goes crazy.
So, in this article, I will propose some simple features and improvements which We can do with our code, to avoid memory leaks and put less pressure on Garbage Collector.
The source code can be found here.
You can continue reading this important article in Medium