if I have stack allocated value types what cleans them up? The GC is only heap right?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With