473,583 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Releas eComObject(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 1158

"Franz" <fr*******@i-hate-spam.com> wrote in message
news:ew******** ******@TK2MSFTN GP15.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.Releas eComObject(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.co m

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

"Franz" <fr*******@i-hate-spam.com> wrote in message
news:ew******** ******@TK2MSFTN GP15.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.Releas eComObject(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.c om> wrote in
message news:%2******** ********@TK2MSF TNGP11.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.co m
|
| "Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
| news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
| >
| > "Franz" <fr*******@i-hate-spam.com> wrote in message
| > news:ew******** ******@TK2MSFTN GP15.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.Releas eComObject(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
5002
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
1730
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: http://support.microsoft.com/default.aspx?scid=kb;EN-US;224070 It references 500. I'm currently working with 404. This is on a hosted site so I have limited capabilities but can probably get the...
1
1159
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 the PDC of the same domain. We have OWA running and most of the functions work just fine. We can download attachments that are already in the...
0
2212
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 I would greatly in debted to. Serializing the object works fine. When I try to deserialize it, I get the following error: A first chance...
2
2093
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 the onreset attribute of the form element. function removeWarningMsg() { if (isIE) { document.all.Warning.style.color =...
0
4572
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) from Microfost MSDN Library for my project "validateXML". When I did "Build" on my project, I got the following fatal error C1010: c:\Documents and...
5
5023
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# examples, and I am not sure what exactly I am doing wrong. From the C# posts it seems that the drawtodc has a bug and you need to redifine it, so i...
18
28727
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, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
2
1729
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 following Office 2003 apps from the quick launch bar: Access, Excel, Outlook, Powerpoint and Word. I used VB.NET 2003. Today, I tried to open an...
6
6346
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 working ? I cannot find a solution yet. THanks <script type="text/javascript" language=javascript> var ie5 = (document.all &&...
0
7890
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7815
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8187
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6573
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5691
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3812
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1418
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.