IDisposable Best Practices for C# Developers

.NET takes care of memory management for you, right? Mostly. But the Garbage Collector needs your help and that's where IDisposable comes in. This course will teach you how to use it correctly to prevent strange errors and crashes in your apps.
Course info
Rating
(38)
Level
Intermediate
Updated
May 13, 2021
Duration
2h 16m
Table of contents
Description
Course info
Rating
(38)
Level
Intermediate
Updated
May 13, 2021
Duration
2h 16m
Description

IDisposable is the only part of the platform where .NET asks for your help. If you don't use IDisposable correctly, the .NET Garbage Collector can't manage memory properly, so your app won't run efficiently, it may have strange errors, and it will eventually crash.

In this course, IDisposable Best Practices for C# Developers, you'll learn to manage object lifetimes and keep your apps running lean. First, you'll see what goes wrong if you don't dispose of objects, and how that can bring your apps down. Then, you'll explore the Garbage Collector to understand how .NET cleans up unused objects. Finally, you'll discover how to implement IDisposable throughout a distributed .NET application. When you’re finished with this course, you’ll have the skills and knowledge of managed and unmanaged memory to keep your .NET apps performing under any load.

About the author
About the author

Elton is an independent consultant specializing in systems integration with the Microsoft stack. He is a Microsoft MVP, blogger, and practicing Technical Architect.

More from the author
Developing .NET Framework Apps with Docker
Intermediate
3h 34m
Jun 25, 2021
C# Extension Methods
Beginner
1h 26m
May 19, 2021
More courses by Elton Stoneman
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hey, how you doing? My name's Elton, and this is IDisposable Best Practices for C# Developers. I'm a Microsoft Azure MVP and a freelance consultant, and I've been using C# since the first release of .NET in 2002. That's nearly 20 years. And in all that experience, some of the most common problems I've seen are from developers not having a good understanding of IDisposable. This course, IDisposable Best Practices for C# Developers, will help you avoid those problems and write code which is high performing, low on resources, and free of hard‑to‑find functional issues. First, you'll learn what the IDisposable interface is, what it's for, and what kind of problems you get if you don't use it correctly. And these aren't edged case issues. You'll see problems with everyday objects like SQL connections and file streams. Next, we'll have a closer look at memory management in .NET, understanding the garbage collector and how it tidies up managed and unmanaged resources. You'll learn how to use the tools in Visual Studio to diagnose problems, and you'll see how to implement IDisposable correctly to avoid them. Then, you'll see how IDisposable fits with modern .NET architecture where you use dependency injection to manage object lifetimes. And you'll learn how you need to work with common objects like DbContexts and HTTP types in that architecture. By the end of the course, you'll have a good understanding of all the best practices for working with IDisposable, and we'll finish up with guidance of what you need to do every day and what you need to remember for less frequent situations. So join me and take your .NET apps to the next level of reliability with IDisposable Best Practices for C# Developers right here, on Pluralsight.