Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  

AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

Automatic memory management

C sharp

+ Font mai mare | - Font mai mic


Trimite pe Messenger
Implicit conversions
Interfaces - declarations, Interface members
Shift operators
Delegates - Delegate declarations
Conditional logical operators
Selection statements

Automatic memory management

C# employs automatic memory management, which frees developers from manually allocating and freeing the memory occupied by objects. Automatic memory management policies are implemented by a garbage collector. The memory management life cycle of an object is as follows:

When the object is created, memory for an object is allocated.

When the object is no longer in use, the object becomes eligible for garbage collection.

During garbage collection, the destructor (§10.12) for the object (if any) is run, and the object’s associated memory is freed.

The garbage collector maintains information about object usage, and uses this information to make memory management decisions, such as where in memory to locate a newly created object, when to reclaim the memory occupied by an object that is no longer in use, and when to relocate an object. Like other languages that assume the existence of a garbage collector, C# is designed so that the garbage collector may implement a wide range of memory management policies. For instance, C# does not require that objects be garbage collected as soon as they are eligible for collection, or that objects be garbage collected in any particular order.

For example, the program

using System;

class A


class B


class Test


creates an instance of class A and an instance of class B. These objects become eligible for garbage collection when the variable b is assigned the value null, since after this time it is impossible for any user-written code to access them. The output could be either

Destruct instance of A
Destruct instance of B


Destruct instance of B
Destruct instance of A

because the language imposes no constraints on the order in which objects are garbage collected.

Politica de confidentialitate



Vizualizari: 484
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2021 . All rights reserved

Distribuie URL

Adauga cod HTML in site