I'm reading this article on MSDN about the new
operator:
https://msdn.microsoft.com/en-us/library/fa0ab757(v=vs.120).aspx
I do not understand this paragraph:
Value-type objects such as structs are created on the stack, while reference-type objects such as classes are created on the heap. Both types of objects are destroyed automatically, but objects based on value types are destroyed when they go out of scope, whereas objects based on reference types are destroyed at an unspecified time after the last reference to them is removed.
What exactly does the bold text mean? What is an "object based on value/reference types"? Is that an object which only contains value members / only reference members?
Edit I don't think the 'What is the heap / stack' is an appropriate duplicate. While the selected answer in that linked thread is highly informative, I loosely understand the differences between the two -- as much as "the stack stores value types, the heap stores reference types". But I was under the impression that a 'value type' would be things like int
or char
; I didn't realize a struct
is included in that, or that a struct
can be defined as "an object based on value types".