Memory Allocation

Structures are value types. This means that they are allocated in the stack. Such behavior provides great efficiency to structures, because when they are no longer necessary, the CLR simply 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:

image

In this scenario, the garbage collection process ...

Get Visual Basic® 2010 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.