C #: Is there an advantage to using resources in the reverse order of their distribution?

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?

+5
source share
5 answers

If your resources are well created, it does not matter (a lot).

. , , , . ( , , .)

, , - , .

: . / , / ( ).

+5

. GarbageCollector , , .

, A B A B, , A B, A, Dispose .

+4

, , , , .

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.
}
+1

'usings' , "" , ( 40 ). , CMOS.

[ MSDN.com Duffius , , . .. ]

0

" , 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)

0
source

All Articles