473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 1150

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Roberta McGervey | last post by:
I have the following code: <Script LANGUAGE=vbscript RUNAT=Server> for i =0 to document.form1.elements.count-1 response.write "test" next
4
by: Roland Hall | last post by:
This question crosses between this group and IIS, so I have included both. I'm referencing a MSFT document: Creating Custom ASP Error Pages:...
1
by: J H | last post by:
Hi. We're running Exchange 5.5 sp4 (5.5.2657.72) running on nt 4 sp6a with all available windows updates. IIS 4.0 is running with SSL Certificates - self signed using NT's Cert Auth Server from...
0
by: Kenneth Baltrinic | last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
2
by: Simon | last post by:
I have recently set up a server certificate on a web site. Under certain conditions I need to change the color of a html span element. I do this using the following javascript function called from...
0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
by: ddd | last post by:
Hi, I am having problems with using the DrawToDC of the MSHTML.iHTMLElementRender in a VB.net application. For some reason I am getting a "catastrophic error". I am basing the code on c#...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
2
by: Howard Kaikow | last post by:
MSFT KB article 302896 includes a step by step example demonstrating how to build an Office COM in VB .NET, Yesterday, I implemented the example and it works correctly when starting each of the...
6
by: TJO | last post by:
Below is some sample code that fades div tags that is not working in IE 6.0.29 on xp sp2. Can anyone help see why the if(ie5) document.getElementById(divID).filters.alpha.opacity lines are not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.