Johnny,
I don't see the connection to interop here, but still...
>What actually happends when class is loaded using Activator.CreateInstance?
It depends on which overload you use. But the end result is that a new
object of the specified type is created and returned to you. It's like
using the new operator, but more dynamic.
>If I create same class using Activator.CreateInstance many times will
>there be multiple instances of that same class created by
>Activator.CreateInstance?
Yes, just like when you use the new operator multiple times.
>If Activator.CreateInstance will create multiple classes when will those
>instances of class be deleted? Do I have to use certain API to delete them
>or will they be garbage collected after they are coming out of scope?
The garbage collector will take care of it, but not when a variable
referening the object goes out of scope. The object will be removed
some time after all references to it are gone.
>Code like below:
>
[quoted text clipped - 6 lines]
>
>Will Class created above deleted here when it comes out of scope?
No. Variable scope and object litefime are entirely different things
in .NET.
>Second question is that if I want that object created by
>Activator.CreateInstance
>is in memory permanently how will I do it?
Permanently meaning until the appdomain is unloaded? Referencing it
with a static variable should keep it alive.
>Is it possible to get reference to same instance using certain API?
No, if that's what you want you should probably use the factory
pattern.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.