How IDisposable, Dispose, and Finalizers work in C#

preview_player
Показать описание
In this video I will do my best to help you fully understand the IDisposable interface, the basic dispose pattern, finalizers, and how your implementations of Dispose interact with the GC and garbage collection when dealing with managed and unmanaged memory.

Source code:

Slides:

#dotnet #csharp #dcomengineering
Рекомендации по теме
Комментарии
Автор

Best explanation of why/when and how to implement IDisposable pattern I've seen ever! Thank you!

pogburke
Автор

Finally a concret implementation for IDisposable pattern.
Thank you very much !

waelmkaddem
Автор

Great video that helped me to freshen up my knowledge about some specifics.

krccmsitp
Автор

I am literally thrilled with your way of explanation, thanks for the excellent work.

highoncoding
Автор

Thank you for the great explanation. I look forward to see your new videos. ❤

PedramElmi
Автор

Thanks a lot for making such a great video. Its really informative and helpful!

shaileshall
Автор

Well, that's a great video. Thanks for the clear explanation!

_grzehotnik
Автор

Thank you for a very good and clear explanation of the IDisposable interface. I have one question though. At 30:46 you are mentioning the call to image.Dispose() as a managed resource. Isn't image here an unmanaged resource that you are disposing? I know you are correct in what you are saying, since the Microsoft documentation is saying the same thing, but I really can't get why it is called 'managed'. I'm very new to C# (coming from Java) so maybe it is obvious to everyone else? :)

mirbogat
Автор

Things to consider for your next presentation: Show your presentation in full screen. Show your code in full screen without windows on all sizes reducing the relevant space to a minimum. And don't use a semi transparent console which just distracts again from the relevant content. That said, well explained and very informative!

vvswow
Автор

Hello, thank you for your presentation, made things clear and simple !

I'm not expert in C# so sorry if I missed something, but I just have one issue I'm a bit confused with : in your example with the derived class, a call to "image.Dispose()" is in the "Dispose" which overrides the one of the base class, however, the Dispose() in the base call already calls "image.Dispose()". I might be wrong but it is as if we attempt to dispose of the same resource twice, because the Dispose of the base class gets called at the end if the overriding Dispose ?

I read the Dispose mechanism is taking care of the call redundancy doing nothing at the second call, but since the image is defined in the base class primarily, does it suffice to have the Dispose of the base class calling the Dispose of the image, and have nothing to dispose in the derived one ?

If so, might I suggest you enhance the example with another image in the derived class (such as "alternateImage" maybe, for example), which I guess would be the sole resource to be freed in the derived Dispose ? It would be interesting because I found even in Microsoft documentation such example is lacking.

Thanks !

luccharest
Автор

Coming from C++, I think .Net GC should also be considered a memory leak. 🤣

mikicerise
Автор

One of the worst videos on Dispose and finalize..if you are a educator explain in a way everyone understands, not just some selected people!

shaswatkumarparida
visit shbcf.ru