What's a "Type"?
Note:
Any data that a programmer can work with is a "type." Another way of saying this is that all data types and classes are types. Everything is a type, including integers, decimals, other scalars, strings, and classes. Any "thing" you can pass around in code is an instance of a type. Classes are special types in that they contain not just data but also code and support object-oriented behaviors such as inheritance. Note:
As classes and other types have their definitions loaded into memory and get verified and compiled, this data goes into allocated memory just like other data that developers allocate in their application. Example: If you create an ArrayList object: [View full width]System.Collections.ArrayList aList = new System.Collections
.ArrayList();
You are doing several things: The code above is represented in your application as IL. This IL gets JIT complied at runtime right before it is first run. The code is placed into allocated memory. When the code gets JITed, the execution engine looks to see whether it has the information for the type System.Collections.ArrayList loaded into memory; if not, memory for this type definition is allocated and it is loaded into memory and associated with the class ArrayList. When the actual code above is run, a constructor for the ArrayList object needs to be run. If this code has not been loaded and JITed yet, memory gets allocated and the constructor's code gets JITed. The code is loaded, verified, and JITed, and the memory for this constructor's code is associated with the ArrayList class' constructor. The same holds true for any type that gets loaded or method that gets called; if the work has not been done before to load it, it will get loaded and compiled as needed, and the memory used to do that is associated with the type. This memory allocation and tracking is important. As you will see below, code and class definition data, just like objects, can get garbage collected. |