all groups > dotnet clr > july 2003 >
You're in the

dotnet clr

group:

Object Instantiation


Object Instantiation Hanuman
7/7/2003 6:19:54 AM
dotnet clr:
I'm trying to understand the details of calling "New" on a
managed object.

In the COM world, calling "New" caused the following
superset of events:
1. The SCM resolves the path to the class in the registry
by using its CLSID.
2. The object's class factory creates its instance in
memory, and the instance's pointer is returned to the
client by the SCM.
3. The client calls the IUnKnown AddRef() method on the
object to increment its internal reference count.

As far as I've been able to determine, the following
events occur when you call "New" on a managed object:
1. The .Net runtime looks for the requested assembly by
querying the GAC first, then any CodeBase entries in
the .config file, and finally by probing.
2. The Garbage Collector allocates space in the managed
heap for an instance of the object.
3. The runtime creates an instance of the object

Questions:
1. Am I missing any steps?
2. COM objects provide class factories for instantiation.
How does the .Net runtime create object instances?

RE: Object Instantiation Hanuman
7/7/2003 3:27:56 PM
Thank you!

[quoted text, click to view]
RE: Object Instantiation simonhal.nospam NO[at]SPAM online.microsoft.com
7/7/2003 10:18:47 PM
Hello,

The following document should describe how assemblies are located:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconassemblies.asp. This should provide you with information as to how
types are resolved.

As for object instantiation, assemblies contain enough information (or
metadata) to fully describe their layout. As a result, the runtime is fully
responsible for allocating and initializing type instantiations based on
type resolution and constructor signatures.

Because of the runtime's garbage collection mechanism, AddRef and Release
are no longer necessary in managed code (barring COM interop, of course).

Cheers,
Simon

--------------------
[quoted text, click to view]


--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
RE: Object Instantiation Calvin
7/8/2003 11:58:22 AM

[quoted text, click to view]

But I've seen something different when you try to
instantiate an object derived from ContextBoundObject.

I used debug to monitor the process. When you call new a
ContextBoundObject

===============
Class A : ContextBoundObject
{
}

A a = new A();
===============
You won't get an object of type A, you will get
__TransparentProxy instead.

a.GetType() is not available at the watch window, but in
local variable window, you will see it's type of
__TransparentProxy.

But if you say:

Type T = a.GetType(); in your code, use your debugger, you
will see T is typeof(A).

It's just weird, I am not sure how the runtime process the
ContextBoundObject.

Calvin


RE: Object Instantiation simonhal.nospam NO[at]SPAM online.microsoft.com
9/30/2003 12:49:48 AM
Calvin,

__TransparentProxy is an internal CLR type used for context bound and
remoted objects. This type often wraps the true type. The debugger only
exposes types and fields, which means that it is not smart enough to unwrap
the object to show you the true type. For a *much* more detailed
explanation of these internal types, please see Chris Brumme's blog entry
on this subject:

http://blogs.gotdotnet.com/cbrumme/PermaLink.aspx/24e9e5f5-9923-4cf9-b097-9c
018c69d5cb

Cheers,
Simon

--------------------
[quoted text, click to view]
AddThis Social Bookmark Button