473,508 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple: Deleting Objects in C# F1 F1 F1...

Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.

kindly help me out...

Thanz in Advance.
Justine
Nov 15 '05 #1
6 10557
"Justine" <am***********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.


Please write 50 times:
- Setting a reference to Nothing does not destroy the object to which it
refers.

The equivalent in C# is:
myRef = null;

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com


Nov 15 '05 #2
100
Hi Justin,

*Nothing* in VB.NET is *null* in C#

HTH
B\rgds
100

"Justine" <am***********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.

kindly help me out...

Thanz in Advance.
Justine

Nov 15 '05 #3
Justine wrote:
Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.


myObject = null;

Fair warning: this does not destroy the object. The VB method doesn't
either.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
Thanz Every one :-)
-----Original Message-----
Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.

kindly help me out...

Thanz in Advance.
Justine
.

Nov 15 '05 #5
Justine,

'Nothing' in vb is 'null' in C#.

Regarding everybody saying that it doesn't destroy the object, this is what
is meant, in case you don't already know this. "Managed code", which is what
C# and VB.NET are, suggests that the .NET Framework will destroy objects at
is own convenience, when it deems it appropriate. This doesn't do much for
optimized memory management, so unmanaged C++ is still ideal to a lot of
programmers, but it takes the pain away from those of us who want to avoid
messing with memory leaks and optimization and such.

In order for the .NET Framework's runtime engine garbage collector to delete
an object, the object must have already fallen out of scope of all
references that are themselves in scope. Marking a variable Nothing or null
*might* make an object flagged for deletion by the garbage collector, in
which case the object will be deleted *soon* but not *immediately*, but it
will not be marked for deletion if any other objects or other variables are
still referencing that object.

So if you have a function/method and you declare a variable within that
block and assign it a new object and neither that object nor its properties
are passed to any other variable anywhere, then you DON'T need to mark the
variable as 'Nothing' or 'null' in order for it to be deleted by the garbage
collector. It will be flagged for deletion when execution falls out of the
scope of that function/method. On the other hand, if the variable is
declared outside of the function/method, the object will be retained until
the variable is marked as 'Nothing' or 'null' or until the object containing
the variable itself becomes marked for deletion, or if it is a static class,
until the variable is marked as 'nothing' or 'null' or the application
terminates.

HTH,
Jon
"Justine" <am***********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.

kindly help me out...

Thanz in Advance.
Justine

Nov 15 '05 #6
Justine,

'Nothing' in vb is 'null' in C#.

Regarding everybody saying that it doesn't destroy the object, this is what
is meant, in case you don't already know this. "Managed code", which is what
C# and VB.NET are, suggests that the .NET Framework will destroy objects at
is own convenience, when it deems it appropriate. This doesn't do much for
optimized memory management, so unmanaged C++ is still ideal to a lot of
programmers, but it takes the pain away from those of us who want to avoid
messing with memory leaks and optimization and such.

In order for the .NET Framework's runtime engine garbage collector to delete
an object, the object must have already fallen out of scope of all
references that are themselves in scope. Marking a variable Nothing or null
*might* make an object flagged for deletion by the garbage collector, in
which case the object will be deleted *soon* but not *immediately*, but it
will not be marked for deletion if any other objects or other variables are
still referencing that object.

So if you have a function/method and you declare a variable within that
block and assign it a new object and neither that object nor its properties
are passed to any other variable anywhere, then you DON'T need to mark the
variable as 'Nothing' or 'null' in order for it to be deleted by the garbage
collector. It will be flagged for deletion when execution falls out of the
scope of that function/method. On the other hand, if the variable is
declared outside of the function/method, the object will be retained until
the variable is marked as 'Nothing' or 'null' or until the object containing
the variable itself becomes marked for deletion, or if it is a static class,
until the variable is marked as 'nothing' or 'null' or the application
terminates.

HTH,
Jon
"Justine" <am***********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Hi All,

I have a very basic doubts about distroying an Object.
In VB.NET we use Nothing. What is the equivalent in C#.

kindly help me out...

Thanz in Advance.
Justine

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
519
by: Thomas Philips | last post by:
I'm teaching myself OOP using Michael Dawson's "Python Programming For The Absolute Beginner" and have a question about deleting objects. My game has two classes: Player and Alien, essentially...
6
2027
by: Thomas Philips | last post by:
I have a question about deleting objects. My game has two classes, Player and Alien, essentially identical, instances of which can shoot at each other. Player is described below class...
181
8600
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
6
2423
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at...
9
1867
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
4
14001
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
51
10215
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
0
989
by: Terry Reedy | last post by:
"Jacob Davis" <j.foster.davis@gmail.comwrote in message news:C673A5C7-9971-4CAA-8CEB-3993C3E93F9C@gmail.com... | I read in some earlier messages that an object in Python is only | removed or freed...
5
505
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
7324
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
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
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...
1
5052
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...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
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...
0
1556
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.