Click here to Skip to main content
15,895,011 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Kenneth Haugland2-Jun-21 5:06
mvaKenneth Haugland2-Jun-21 5:06 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
honey the codewitch2-Jun-21 3:33
mvahoney the codewitch2-Jun-21 3:33 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Jörgen Andersson2-Jun-21 7:49
professionalJörgen Andersson2-Jun-21 7:49 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Mircea Neacsu2-Jun-21 3:41
Mircea Neacsu2-Jun-21 3:41 
GeneralRe: Why every developer should learn computer science theories first. NOT! PinPopular
obermd2-Jun-21 6:14
obermd2-Jun-21 6:14 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Sander Rossel2-Jun-21 21:01
professionalSander Rossel2-Jun-21 21:01 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
obermd4-Jun-21 5:10
obermd4-Jun-21 5:10 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Sander Rossel5-Jun-21 3:03
professionalSander Rossel5-Jun-21 3:03 
Yes, which in C# only happens when you're using poorly written libraries.
You should know to call Dispose (and sometimes Close too (except on HttpClients, which you should create using the IHttpClientFactory, which returns them to the pool) (except when the object is still being used by some middle ware, like a file handle when returning a file in ASP.NET) (or when an object's lifetime is handled by another object, such as some use cases of DbCommand, DbDataAdapter, etc. or generated such as controls in WinForms designers) (oh yeah, and also don't call Dispose on most iterators, which you generally shouldn't use directly anyway, but which are only disposable for COM support, which is hardly ever applicable) (also don't call Close or Dispose when they throw a NotImplementedException, which I've seen a couple of times because some interface inherited IDisposable, but the implementation didn't need it)) and that's about it, simple Laugh | :laugh:
Even forgetting to explicitly Dispose and/or Close (which are usually synonymous, but not always) will usually result in the resources being released by the garbage collector.

I recently had a leak in Crystal Reports.
Not closing and disposing a report object, even when it's handled by a report viewer, results in too many temp objects, which will ultimately, sometimes, results in an out of memory exception or some such.
(Had a nice debugging session using the WeakReference<T> class to figure out that one Laugh | :laugh: )
But that's Crystal Reports and I've had unidentifiable substances under my shoe which were better thought through than Crystal Reports.

Anyway, even knowing all this, all you can really do, and should do, in C#, is call Dispose, which is kind of my point.
You don't even have to know why, just know that you should.
Even when you're a C or C++ pro, you shouldn't use unsafe in C# unless you really have no other choice, and I've always had.

Your options are even more limited in a language such as JavaScript, making this knowledge even more useless in your day-to-day programming.

However, when you know what you're doing, you can write articles such as this one, which is nice I suppose: The Dispose(bool disposing) Pattern is Broken[^]
For everyone else, and even for this author, just call Dispose and be done with it.

GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
PIEBALDconsult2-Jun-21 6:26
mvePIEBALDconsult2-Jun-21 6:26 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Gerry Schmitz2-Jun-21 10:31
mveGerry Schmitz2-Jun-21 10:31 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Sander Rossel2-Jun-21 21:07
professionalSander Rossel2-Jun-21 21:07 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Eddy Vluggen3-Jun-21 11:45
professionalEddy Vluggen3-Jun-21 11:45 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
5teveH3-Jun-21 20:08
5teveH3-Jun-21 20:08 
GeneralRe: Why every developer should learn computer science theories first. NOT! Pin
Eddy Vluggen3-Jun-21 23:54
professionalEddy Vluggen3-Jun-21 23:54 
NewsAmazing Opportunity (cellarbration meal) Pin
Super Lloyd1-Jun-21 22:49
Super Lloyd1-Jun-21 22:49 
GeneralRe: Amazing Opportunity (cellarbration meal) Pin
Richard MacCutchan2-Jun-21 1:20
mveRichard MacCutchan2-Jun-21 1:20 
GeneralRe: Amazing Opportunity (cellarbration meal) Pin
W Balboos, GHB2-Jun-21 1:47
W Balboos, GHB2-Jun-21 1:47 
GeneralRe: Amazing Opportunity (cellarbration meal) Pin
Super Lloyd2-Jun-21 2:00
Super Lloyd2-Jun-21 2:00 
GeneralRe: Amazing Opportunity (cellarbration meal) Pin
dandy722-Jun-21 4:08
dandy722-Jun-21 4:08 
GeneralRe: Amazing Opportunity (cellarbration meal) Pin
Super Lloyd2-Jun-21 5:25
Super Lloyd2-Jun-21 5:25 
NewsAmazing Opportunities (continued) PinPopular
Super Lloyd1-Jun-21 22:05
Super Lloyd1-Jun-21 22:05 
GeneralRe: Amazing Opportunities (continued) Pin
honey the codewitch1-Jun-21 22:11
mvahoney the codewitch1-Jun-21 22:11 
GeneralRe: Amazing Opportunities (continued) Pin
Super Lloyd1-Jun-21 22:26
Super Lloyd1-Jun-21 22:26 
GeneralRe: Amazing Opportunities (continued) Pin
Slacker0071-Jun-21 22:43
professionalSlacker0071-Jun-21 22:43 
GeneralRe: Amazing Opportunities (continued) PinPopular
honey the codewitch2-Jun-21 2:12
mvahoney the codewitch2-Jun-21 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.