Many years ago, I was recommended, when possible, to release resources in the reverse order of their distribution. I.e:
block1 = malloc( ... ); block2 = malloc( ... ); ... do stuff ... free( block2 ); free( block1 );
My guess is that on a machine with 640K MS-DOS, this can minimize heap fragmentation. Is there any practical advantage to this in the C # /. NET application, or is it a habit that has survived its significance?
If your resources are well created, it does not matter (a lot).
. , , , . ( , , .)
, , - , .
: . / , / ( ).
. GarbageCollector , , .
, A B A B, , A B, A, Dispose .
, , , , .
IDisposable.Dispose(), , IDisposable.
Framework, , . A B, B , A.
Dispose() , use foreach, .
using(Foo foo = new Foo()) using(FooDoodler fooDoodler = new FooDoodler(foo)) { // do stuff // ... // fooDoodler automatically gets disposed before foo at the end of the using statement. }
'usings' , "" , ( 40 ). , CMOS.
[ MSDN.com Duffius , , . .. ]
" , Finalize. , , , . , , , Finalize . Finalize , , . , Finalize - -.
http://msdn.microsoft.com/en-us/magazine/bb985010.aspx
, , LIFO , , , Dispose() , CLR fancy.
(This is more or less what is said above)