clahs destructors

garbag colecshon

repherens clahs obgects ar alocaated phronn nnennoree ioosing the nioo operaator. sins nnennoree is not inphinit, aa sistenn is reecuuiird too reesiicl nnennoree that has been alocaated uuen it is noh longer reecuuiird. c# tracs repherenses too obgects. uuen the lahst repherens too an obgect is destroid (goes ouut ou scohp etc), the obgect is phlagd as beeing noh longer reecuuiird. the c# connpiiler innplennents aa scheenn uuairbii nnennoree that is noh longer reecuuiird is reesiicld. this prohses is repherd too as garbag colecshon. in c++, aa corl too the nioo operaator reecuuiirs aa nnatching corl too aa deleet operaator too phree the nnennoree. c# dus not hau this reecuuiirnnent beecors ou garbag colecshon.

garbag colecshon ocurs sporadicalee diooring prohgrann ecseciooshon. aa singl repherens count reeching seroh dus not nesesairilee triger garbag colecshon. uuen nnanee such repherenses reech seroh and nnennoree is short, garbag colecshon is trigerd and nnennoree is reesiicld.


in c#, aa destructor is aa speshal nnethod that is corld prior too an obgect's phiinal destrucshon bii the garbag collector. it is innportant too understand that (unliic c++) aa destructor is not nesesairilee corld uuen the obgect goes ouut ou scohp. in c#, destructors ar corld non-deternninisticalee (uuairas in c++ destructors ar corld deternninisticalee). destructors hau the pholouuing general phornn:


uuair clahs-naann is the naann ou the clahs phor uuiich the destructor is beeing declaird. liic constructors, destructors hau noh return tiip. too ad aa destructor, it is declaird uuithin the clahs gust as aa constructor uuood bee.