473,385 Members | 1,606 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,385 software developers and data experts.

constructor / destructur

I'm new in csharp.
I create a SortedList with new objects.
I don't use this SortedList and their objects any more.

Have I to set all objects in the destructor to null?
Or do it the .Net framework for me?

Thanks Thomas
Nov 16 '05 #1
8 1150
..NET uses a mark-and-sweep garbage collector. There are rare cases in
which you do need to manually dispose of things, but they are few and
far between.

After the variable that contains the reference to your SortedList goes
out of scope, the garbage collector will automatically clean it up.

Nov 16 '05 #2
Out of interest what exactly should you, and should you not, dispose of?
Is it always a good idea to call Dispose on anything that implements
IDisposable or are the rules more lenient?

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
.NET uses a mark-and-sweep garbage collector. There are rare cases in
which you do need to manually dispose of things, but they are few and
far between.

After the variable that contains the reference to your SortedList goes
out of scope, the garbage collector will automatically clean it up.

Nov 16 '05 #3
thanks thomas

"Uchiha Jax" <i_************************@NOSPAMhotmail.com> schrieb im
Newsbeitrag news:4n***************@newsfe3-win.ntli.net...
Out of interest what exactly should you, and should you not, dispose of?
Is it always a good idea to call Dispose on anything that implements
IDisposable or are the rules more lenient?

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
.NET uses a mark-and-sweep garbage collector. There are rare cases in
which you do need to manually dispose of things, but they are few and
far between.

After the variable that contains the reference to your SortedList goes
out of scope, the garbage collector will automatically clean it up.


Nov 16 '05 #4
Uchiha Jax <i_************************@NOSPAMhotmail.com> wrote:
Out of interest what exactly should you, and should you not, dispose of?
Is it always a good idea to call Dispose on anything that implements
IDisposable or are the rules more lenient?


I believe it's a good idea to call Dispose on anything that implements
IDisposable if your code is the owner of it (and unfortunately that's
sometimes not clear).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
not always...

The using statement disposes of the resource

A using statement of the form

using (R r1 = new R()) {
r1.F();
}

is precisely equivalent to

R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}

Regards,
Nirosh.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
Uchiha Jax <i_************************@NOSPAMhotmail.com> wrote:
Out of interest what exactly should you, and should you not, dispose of?
Is it always a good idea to call Dispose on anything that implements
IDisposable or are the rules more lenient?


I believe it's a good idea to call Dispose on anything that implements
IDisposable if your code is the owner of it (and unfortunately that's
sometimes not clear).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
Champika Nirosh <te**@test.lk> wrote:
not always...

The using statement disposes of the resource

A using statement of the form

using (R r1 = new R()) {
r1.F();
}

is precisely equivalent to

R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}


I'm not sure what your point is. Yes, the using statement is the
easiest way to call Dispose, but that's still calling Dispose...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
My initial thought was that u implied to call Dispose manually.. and second
is "using" statement is not always call Dispose, if a null resource is
acquired, then no call is made to Dispose. Anyway I think your statement
covers this seemlessly

Regards,
Nirosh.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Champika Nirosh <te**@test.lk> wrote:
not always...

The using statement disposes of the resource

A using statement of the form

using (R r1 = new R()) {
r1.F();
}

is precisely equivalent to

R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}


I'm not sure what your point is. Yes, the using statement is the
easiest way to call Dispose, but that's still calling Dispose...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #8
My initial thought was that u implied to call Dispose manually.. and second
is "using" statement is not always call Dispose, if a null resource is
acquired, then no call is made to Dispose. Anyway I think your statement
covers this seemlessly

Regards,
Nirosh.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Champika Nirosh <te**@test.lk> wrote:
not always...

The using statement disposes of the resource

A using statement of the form

using (R r1 = new R()) {
r1.F();
}

is precisely equivalent to

R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}


I'm not sure what your point is. Yes, the using statement is the
easiest way to call Dispose, but that's still calling Dispose...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9

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

Similar topics

3
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
12
by: Marcelo Pinto | last post by:
Hi all, In practice, what is the diference between a default constructor and an explicit default constructor? class Ai { public: Ai() {} };
18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
8
by: shuisheng | last post by:
Dear All, I am wondering how the default copy constructor of a derived class looks like. Does it look like class B : public A { B(const B& right) : A(right) {}
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
13
by: sam_cit | last post by:
Hi Everyone, I have the following unit to explain the problem that i have, class sample { public : sample() { printf("in sample...\n"); }
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.