Hello All
One of my friend told me that dynamic method is the only way if you want to at run time construct code that can be garbage collected.
One question in my mind that how garbage collector garbage the object which generated using reflection?
Hello All
One of my friend told me that dynamic method is the only way if you want to at run time construct code that can be garbage collected.
One question in my mind that how garbage collector garbage the object which generated using reflection?
An object constructed using reflection will be garbage collected like any other type of object, for example when it leaves the scope of a method if it's a method variable.
how should an object created by reflection be different than one created normally?
you have an instance variable of this object... the runtime exactly knows what type of object it is, and also does the GC.
only the way the object is created is different. the object should be exactly the same as one created with new MyObject()
Garbage collection will collect any .NET objects. It doesn't differ wether they are created using reflection or not.
Any piece of code that runs under the control of CLR is managed code and CLR governs and decides for garbage collection. there are ways in which you can coltrol the Garbage collection but unless it is really required let CLR decide.