Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do ValueTypes cause GC?

if I have stack allocated value types what cleans them up? The GC is only heap right?

like image 294
DayTwo Avatar asked Feb 10 '11 08:02

DayTwo


1 Answers

If the values are on the stack, then when the current stack frame is "popped" (by the method returning) the values are effectively cleaned up... there won't be any finalizers called or anything like that, but the memory used up by those values will be reused next time the stack gets that high.

Note that value types aren't always allocated on the stack, however. In particular, they're often allocated as part of other objects (e.g. a class with an int member) or they can be boxed.

like image 109
Jon Skeet Avatar answered Sep 20 '22 00:09

Jon Skeet