c# - How the "using" keyword Improves Performance (memory or speed wise) -


i working on image processing scripts in .net , came across following article outlining how crop, resize, compress, etc.

in first comment, states methods used in article imaging notorious memory leaks:

a quick warning thinking using system.drawing (or gdi+) in asp.net environment. it's not supported microsoft , msdn (as of recently) states may experience memory leaks.

then, in second comment, article author says "i've handled problem":

just make clear code above isn't thrown together. evolved time because suggested easy mistakenly create performance issues when using gdi+. just see how many times i've written 'using' above!

i wondering how (or if) use of using handles (or improves) memory leak problems referenced in first comment.

the using statements don't anything performance wise. calling dispose method on objects using declared on.

calling dispose allow unmanaged resources, gdi+ creates image operations, unallocated. free memory , windows handles. both can contribute application stop working correct, because if run out of memory or handles, program have trouble running.

a using statement equivalent (and compiled eventually):

var x = ...; // code using intialization try {     ... // code inside using statement } {     ((idisposable)x).dispose(); } 

this makes sure object disposed, if exception occurs.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -