IDisposable Exposed

  Рет қаралды 3,327

Shiv Kumar

Shiv Kumar

Күн бұрын

Пікірлер: 28
@Hect0rx
@Hect0rx 2 жыл бұрын
Great video and topic as always, one of the few channels here on KZbin that deliver professional in-depth content
@Matlus
@Matlus 2 жыл бұрын
Thank you Arghs! Your comment is much appreciated.
@Karen-mj9kk
@Karen-mj9kk Жыл бұрын
Best explanation I've found about IDisposable. Thank you!
@suhasinin9145
@suhasinin9145 2 жыл бұрын
Great video! Havent seen anybody who has digested the stuff and can explain it so clearly and calmly.
@Matlus
@Matlus 2 жыл бұрын
Thank you Suhasini! Glad you liked it and found it useful.
@hansrudolf5849
@hansrudolf5849 2 жыл бұрын
Looking forward to that video - let's see if I can learn one or two new things. Thanks for your time Shiv.
@Matlus
@Matlus 2 жыл бұрын
Hi Hans, let me know what you think!
@schwamm1996kopf
@schwamm1996kopf 2 жыл бұрын
Thank you for the video, really well explained. I have a question: Does it make sense to use IDisposable on Singletons? I thought Singleton Instances live for the lifetime of the whole application and after the application shuts down, the os would free up the resources. So what's the reason to use IDisposable on Singletons?
@adriangas_
@adriangas_ 2 жыл бұрын
In a company that I used to work for, developers loved to use null-conditional operators everywhere 'just in case' and that code was a nightmare to debug, because of those null-conditionals masking the real problem and leaving you with totally unrelated null reference exceptions much later.
@Matlus
@Matlus 2 жыл бұрын
Yes, I've heard of situations where the null conditional operator has introduced bugs. Yesterday on one of my teams a dev had used it and I was explaining why she should remove it and that went on to an interesting conversation. I think I'll make video on this topic :)
@akimbbo_upnext
@akimbbo_upnext 2 жыл бұрын
I like how you pay attention to this nullability detail at 18:30. In my project that i work on people are overusing this operator just to supress warnings:(
@Matlus
@Matlus 2 жыл бұрын
Thanks for writing in and confirming that this sort of thing happens a lot.
@SBDavin
@SBDavin 2 жыл бұрын
I commend you for taking on this fascinating topic! I always thought finalizers should be added to our disposable classes, with the hope they will not be used. For example, if a programmer uses our class but mistakenly forgets to call Dispose(), then the instance remains on the freachable queue where eventually threadpool threads execute the queued finalizer(s) to properly dispose our object(s) and then removes the root reference to our instance so it can eventually be garbage collected. As you said, that's why we need SuppressFinalize(), so that finalization can be skipped and memory used by the object can be recompacted much sooner. IMHO, disassembling the Close() and Dispose() methods of the used data provider connection object is recommended to see what is really happening under the covers. Many times Dispose() calls Close() for us automatically. BTW - there are some real garbage collection nerds out, even GC publications and conferences. I'm still a novice but I'm fascinated with the science. Digging into memory pressure and generation counts could be a whole other video. Thank you, Shiv, for the great video!
@Matlus
@Matlus 2 жыл бұрын
Hi Davin, >I always thought finalizers should be added to our disposable classes, with the hope they will not be used. That could be a viable strategy, though I've never used it (or seen it used) myself. So do you call the private Dispose(bool disposing) method passing in false as the argument from your finalizer? Yes, Dispose calls Close. I guess the point was really trying to make was that they do different things (close releases the connection back to the pool). In my actual code on GitHub, I don't actually call close. I simply dispose.
@SBDavin
@SBDavin 2 жыл бұрын
@@Matlus Yes - the finalizer typically passes false to Dispose() to release the unmanaged resources (file handles, window handles, libraries, etc.) Thank you, sir.
@Matlus
@Matlus 2 жыл бұрын
Cool!
@ThomasOkyere-n2h
@ThomasOkyere-n2h 11 күн бұрын
I love your videos
@obiwanjacobi
@obiwanjacobi 2 жыл бұрын
It's good to mention that the AppDomain is only used in the (old/legacy) dotnet Framework. Dotnet Core and .NET5 and .NET6 do not use AppDomains. It's also good to know that the dispose pattern is only there for derived classes to be able to call all the dispose logic of the entire class hierarchy in combination with Finalization. If your class is sealed (as in this example) it cannot be derived from and you do not need to implement the dispose pattern.
@Matlus
@Matlus 2 жыл бұрын
Hi Marc, good point about sealed classes and the dispose pattern, I should have made mention of it, true. However, I implement the pattern in sealed classes nonetheless. As regards AppDomains, they're still there. You can't create (more) app domains like you could in earlier versions. At least that's how I understand it.
@MrJonnis13
@MrJonnis13 2 жыл бұрын
Welcome Back Shiv :) Can you please clarify the "AppDomain" difference between a console application and a Asp.Net web application ? How and why in the latter case, my code is running in multiple AppDomains ?
@Matlus
@Matlus 2 жыл бұрын
Thank you Johnny! ASP.NET applications run in another process (a worker process called W3p.exe) and generally, for a given "Web Application" you'd configure your web application to use multiple worker processes to handle the workload. Typically one per the number of CPU cores available on the server. Thus your application is running in multiple app domains (one per worker process). Hopefully that makes sense?
@MrJonnis13
@MrJonnis13 2 жыл бұрын
@@Matlus That's making it crystal clear! Thank you Shiv
@matthewparker7789
@matthewparker7789 Жыл бұрын
Great video: only 13k subs ? :-(
@glaysonpatricio
@glaysonpatricio 2 жыл бұрын
Tks...
@Matlus
@Matlus 2 жыл бұрын
You're welcome Glayson.
Let's Talk - Null Conditional Operator. No Thank you!
20:28
Shiv Kumar
Рет қаралды 2,2 М.
To LINQ Or Not To LINQ - That is the Question
32:35
Shiv Kumar
Рет қаралды 3,3 М.
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 27 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 25 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 54 МЛН
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 11 МЛН
Logging And Application Insights in Non-ASP.NET Applications
33:52
High Performance Logging and Custom Objects
29:07
Shiv Kumar
Рет қаралды 1,6 М.
Let's Talk - Always use the "as" operator - No Thank you
35:20
Shiv Kumar
Рет қаралды 1,4 М.
Service Interface Layer Pattern
38:52
Shiv Kumar
Рет қаралды 3,4 М.
SOLID IS OLD!! - Dependency Inversion Principle
55:03
Shiv Kumar
Рет қаралды 4,9 М.
Unit Testing Strategy
48:06
Shiv Kumar
Рет қаралды 3,1 М.
Custom Loggers. Importance of Logging Off Application Servers
37:11
Introduction To gRPC
50:27
Shiv Kumar
Рет қаралды 6 М.
gRPC - Real-World .NET Core/.NET 5 Applications
49:40
Shiv Kumar
Рет қаралды 3,1 М.
gRPC - Getting Started .NET 5/ .NET Core 3.x
1:01:00
Shiv Kumar
Рет қаралды 3,8 М.
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 27 МЛН