471,317 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Is it an error on msdn document?

http://support.microsoft.com/?kbid=317109

In this document, the NAR method for C# is as follow.

private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch {}
finally
{
o = null;
}
}

What is the use of the line "o = null"? Since the parameter is not a ref
object, it can't change the value of o. Is it a COM issue?
Feb 15 '06 #1
3 1117

"Franz" <fr*******@i-hate-spam.com> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
| http://support.microsoft.com/?kbid=317109
|
| In this document, the NAR method for C# is as follow.
|
| private void NAR(object o)
| {
| try
| {
| System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
| }
| catch {}
| finally
| {
| o = null;
| }
| }
|
| What is the use of the line "o = null"? Since the parameter is not a ref
| object, it can't change the value of o. Is it a COM issue?
|
|

The argument o is a copy of the callers object reference, so here the value
of the copy is set to null. While it's not an error to do so, it's also not
necessary as it will be done automatically at object return.

Willy.
Feb 15 '06 #2
Also, in a non-debug build, it may actually prolong the lifetime of the
object.

In the end, that line is pointless.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

"Franz" <fr*******@i-hate-spam.com> wrote in message
news:ew**************@TK2MSFTNGP15.phx.gbl...
| http://support.microsoft.com/?kbid=317109
|
| In this document, the NAR method for C# is as follow.
|
| private void NAR(object o)
| {
| try
| {
| System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
| }
| catch {}
| finally
| {
| o = null;
| }
| }
|
| What is the use of the line "o = null"? Since the parameter is not a
ref
| object, it can't change the value of o. Is it a COM issue?
|
|

The argument o is a copy of the callers object reference, so here the
value
of the copy is set to null. While it's not an error to do so, it's also
not
necessary as it will be done automatically at object return.

Willy.

Feb 15 '06 #3
True, and it's rather common to see this in code originally written in VB,
converted to VB.NET and finally translated into C#.

Willy.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
| Also, in a non-debug build, it may actually prolong the lifetime of the
| object.
|
| In the end, that line is pointless.
|
| --
| - Nicholas Paldino [.NET/C# MVP]
| - mv*@spam.guard.caspershouse.com
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| >
| > "Franz" <fr*******@i-hate-spam.com> wrote in message
| > news:ew**************@TK2MSFTNGP15.phx.gbl...
| > | http://support.microsoft.com/?kbid=317109
| > |
| > | In this document, the NAR method for C# is as follow.
| > |
| > | private void NAR(object o)
| > | {
| > | try
| > | {
| > | System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
| > | }
| > | catch {}
| > | finally
| > | {
| > | o = null;
| > | }
| > | }
| > |
| > | What is the use of the line "o = null"? Since the parameter is not a
| > ref
| > | object, it can't change the value of o. Is it a COM issue?
| > |
| > |
| >
| > The argument o is a copy of the callers object reference, so here the
| > value
| > of the copy is set to null. While it's not an error to do so, it's also
| > not
| > necessary as it will be done automatically at object return.
| >
| > Willy.
| >
| >
|
|
Feb 15 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Roland Hall | last post: by
6 posts views Thread by TJO | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.