473,831 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to destroy arrays

Hi,

I have created an array of Objects in a collection. I was wondering is there
a way to destroy the array to free up the space in the memory ? or they are
automatically destroyed and garbagge collected by .Net framework?

Sarfraz
Jul 21 '05 #1
43 2714
Everything in .NET is a type (either reference or value types). All types
are managed by the Garbage Collector. There is no need to "free up memory"
as this is the purpose of the GC. There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make
the object = Nothing.
"Sarfraz Hooda" <sh****@iqueri. com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have created an array of Objects in a collection. I was wondering is there a way to destroy the array to free up the space in the memory ? or they are automatically destroyed and garbagge collected by .Net framework?

Sarfraz

Jul 21 '05 #2
Scott M. <s-***@nospam.nosp am> wrote:
Everything in .NET is a type (either reference or value types). All types
are managed by the Garbage Collector. There is no need to "free up memory"
as this is the purpose of the GC. There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make
the object = Nothing.


Usually that's unnecessary, however, as the garbage collector can tell
when a variable is last used in the IL. Unless you're in a particularly
special case (eg where a variable is used in the first iteration of a
long loop, and not thereafter) it's best not to clutter up your code
setting variables to null/Nothing.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
Hi Jon,

Maybe this is higher English; however can you tell me where your message is
different from that from Scott?

I found Scotts message very clear and I agree completely with him in the way
he wrote it.

Cor
Everything in .NET is a type (either reference or value types). All types are managed by the Garbage Collector. There is no need to "free up memory" as this is the purpose of the GC. There are certain circumstances though, when you may want the object in question to fall out of scope immediately, rather than waiting for the end of a procedure. In this case you could make the object = Nothing.


Usually that's unnecessary, however, as the garbage collector can tell
when a variable is last used in the IL. Unless you're in a particularly
special case (eg where a variable is used in the first iteration of a
long loop, and not thereafter) it's best not to clutter up your code
setting variables to null/Nothing.

Jul 21 '05 #4
In addition, VB has an Erase statement, which should deallocate memory used
for the array's elements.

Brian Davis
http://www.knowdotnet.com

"Scott M." <s-***@nospam.nosp am> wrote in message
news:eS******** ********@TK2MSF TNGP09.phx.gbl. ..
Everything in .NET is a type (either reference or value types). All types
are managed by the Garbage Collector. There is no need to "free up memory" as this is the purpose of the GC. There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make the object = Nothing.
"Sarfraz Hooda" <sh****@iqueri. com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have created an array of Objects in a collection. I was wondering is

there
a way to destroy the array to free up the space in the memory ? or they

are
automatically destroyed and garbagge collected by .Net framework?

Sarfraz


Jul 21 '05 #5
I think it's about code like:

{
SomeBigObject x = new SomeBigObject() ;
DoSomethingWith X(x);
// x = null;
DoSomethingElse ThatTakesReally LongButDoesntUs eX();
}

Now, (as far as I got him) Jon tried to explain that there's NO use in
setting "x" to null/nothing, as the GC can tell it won't get used after line
2 anyway. I didn't read that in the previous post.

Of course, this only applies to local variables.

Niki

"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:Oq******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi Jon,

Maybe this is higher English; however can you tell me where your message is different from that from Scott?

I found Scotts message very clear and I agree completely with him in the way he wrote it.

Cor
Everything in .NET is a type (either reference or value types). All types are managed by the Garbage Collector. There is no need to "free up memory" as this is the purpose of the GC. There are certain circumstances though, when you may want the object in question to fall out of scope immediately, rather than waiting for the end of a procedure. In this case you could make the object = Nothing.


Usually that's unnecessary, however, as the garbage collector can tell
when a variable is last used in the IL. Unless you're in a particularly
special case (eg where a variable is used in the first iteration of a
long loop, and not thereafter) it's best not to clutter up your code
setting variables to null/Nothing.


Jul 21 '05 #6
Hi Niki,

I think not and although Scott did not mention it, what he told can count
even more for globally used objects.

I agree with Scott and Jon that it should not be done normally, however as
Scott already stated I believe that there are circumstances that it can be
done.

Cor
I think it's about code like:

{
SomeBigObject x = new SomeBigObject() ;
DoSomethingWith X(x);
// x = null;
DoSomethingElse ThatTakesReally LongButDoesntUs eX();
}

Now, (as far as I got him) Jon tried to explain that there's NO use in
setting "x" to null/nothing, as the GC can tell it won't get used after line 2 anyway. I didn't read that in the previous post.

Of course, this only applies to local variables.

Jul 21 '05 #7
Cor Ligthert <no**********@p lanet.nl> wrote:
Maybe this is higher English; however can you tell me where your message is
different from that from Scott?

I found Scotts message very clear and I agree completely with him in the way
he wrote it.


Niki's message was spot on. Setting a variable to null/Nothing is less
useful than most people think - even for long-running methods, there
are only a few situations where it's of use.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Quoted from Scott M.:
There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make the object = Nothing.
This implies that usually objects will be garbage collected when they fall
out of scope, that is, at the end of the procedure.
Strictly speaking, that's wrong for both local AND member variables: local
variables might get collected BEFORE the end of the procedure (as Jon
explained), and member variables survive the end of a procedure if they're
not set to null/nothing.

I guess Scott was aware of these facts, but nonetheless, the correction was
ok.

Niki

"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi Niki,

I think not and although Scott did not mention it, what he told can count
even more for globally used objects.

I agree with Scott and Jon that it should not be done normally, however as
Scott already stated I believe that there are circumstances that it can be
done.

Cor
I think it's about code like:

{
SomeBigObject x = new SomeBigObject() ;
DoSomethingWith X(x);
// x = null;
DoSomethingElse ThatTakesReally LongButDoesntUs eX();
}

Now, (as far as I got him) Jon tried to explain that there's NO use in
setting "x" to null/nothing, as the GC can tell it won't get used after

line
2 anyway. I didn't read that in the previous post.

Of course, this only applies to local variables.


Jul 21 '05 #9
Hi Jon,

Constructive quoting again from you, I once gave you a sample that more
people can do that however decent people do not do that.

Leaving the message from Scott out from this makes it the same as if Scott
was telling that the Tower Bridge was in Paris.

The message you give the same answer again as Scott was saying, while you
give the idea that he did not.
Maybe this is higher English; however can you tell me where your message is different from that from Scott?

I found Scotts message very clear and I agree completely with him in the way he wrote it.


Niki's message was spot on. Setting a variable to null/Nothing is less
useful than most people think - even for long-running methods, there
are only a few situations where it's of use.


Jul 21 '05 #10

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

Similar topics

2
26270
by: Rob | last post by:
My first GUI so be gentle... When I start my program I call a class that runs the initial window. While in this class if a certain button is pressed it calls a function outside the class. This function then initially calls another function to "root.destroy()". Basically I want the current window gone so the function I just called can open it's own window. The problem I'm stuck with is that once this function is done and I need to close...
6
18002
by: max(01)* | last post by:
hi people. when i create a widget, such as a toplevel window, and then i destroy it, how can i test that it has been destroyed? the problem is that even after it has been destroyed, the instance still exists and has a tkinter name, so testing for None is not feasible: >>> import Tkinter >>> fin = None >>> fin1 = Tkinter.Toplevel()
2
6287
by: Ook | last post by:
I was taught that in a copy constructor, you don't have to destroy your arrays, but in an overloaded assignment operator, you have to. Example: When do you delete, and when do you not? Is it arbitrary, or are there general guidelines that should be followed? I'm thinking that in the copy constructor, you are creating a new instance of the class, and in the assignment, you have already created the class and therefore have to destroy...
8
1952
by: vvenk | last post by:
Hello: I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and then the system does not work anymore until I kill that process. Obviously, this is not acceptable. Looking back, I do not destroy any objects in my form. Would that be the reasn why the application breaks down?
43
508
by: Sarfraz Hooda | last post by:
Hi, I have created an array of Objects in a collection. I was wondering is there a way to destroy the array to free up the space in the memory ? or they are automatically destroyed and garbagge collected by .Net framework? Sarfraz
2
1554
by: Flavio | last post by:
Hi, I have a miniframe composed mainly of combo boxes, that I need to destroy and recreate multiple time with different choice lists for the combo boxes. My problem is that even after destroying a miniframe with the Destroy() method, when it is recreated, the combo boxes show the same lists of its previous incarnation...
15
4643
by: Mark C | last post by:
I know a string is immutable, but is there any trick or any other way to destroy a string Thanks www.quiznetonline.com
6
4032
by: muppetjones | last post by:
I'm pretty new at this, and I'm trying to figure out how Perl's classes work with signals. Specifically, it doesn't seem that a class's DESTROY function is called when you Ctrl-C the program. I tried using use sigtrap qw(handler DESTROY INT QUIT);, but I'm not even sure this is the proper way to catch the signal. Either way, it seems I no longer receive a reference to my object when DESTROY is called. I keep getting this error: Can't...
3
6522
by: drzoo2 | last post by:
Completely noob question as I am not a programmer but really trying hard to learn Python (Object oriented programming in general). I am writing a program in python that calls a popup window with some general information with an ok button. If I close the window using the window's close button I have no problems but If I call the same destroy function using the button call, it will not kill the popup. def destroy(self, widget, data=None):...
0
9793
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10777
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10534
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7748
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
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

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.