C#C
C#12mo ago
48 replies
Faker

✅ using keyword for resource management in C#

Hello guys, I just learnt about the
using
keyword for resource management in C#. What I understood about it is that whenever we are done with using specific resources, like dealing with database operations, the
using
keyword automatically dispose/free memory (please add up to the use of this keyword if I'm missing anything or incorrectly saying things). I have one question though. I read that even though if our console application crashes,
IF
we are not using the
using
keyword or try-catch-finally block, the resource allocated isn't freed immediately, like it's still allocated to SQL Server for example. I'm a bit lost here, our app is no longer "alive", then how come resources is still available to our SQL server database.

Also, when using the
using
keyword, we don't need to close the database connection like
connection.close()
anymore? This is already been taken care of under the hood?
Was this page helpful?