Should be pretty self-explanatory, but this is in the context of real-time XNA code where I want to avoid allocations in order to avoid triggering GC. So I’m wondering if the managed Type objects associated with the types that have been loaded are always present in the runtime, or if typeof() actually constructs a new Type object (presumably from some unmanaged metadata in the runtime) on the heap, which will be garbage collected. Feel free to point out any ignorant assumptions/misconceptions revealed by even asking this question as well =)
Should be pretty self-explanatory, but this is in the context of real-time XNA code
Share
No, types are cached, it returns always the same static readonly instance.
You can write this sample test program to verify this 🙂
The same apply for GetType method and for every other reflection function, like getting properties, methods, fields, attributes and everything else.