Memory Allocation
Structures are value types. This means they are allocated in the stack. Such behavior provides great efficiency to structures because when they are no longer necessary, the Common Language Runtime (CLR) removes them from the stack and avoids the need of invoking the garbage collector as happens for reference types. But this is just a general rule. Structures’ members can expose any kind of .NET type and therefore reference types, too. The following revisited implementation of the Order
structure provides an example, exposing an OrderDescription
property of type String
that is a reference type:
Public Structure Order Public Property OrderID As Integer Public Property OrderDate As Date Public ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.