473,943 Members | 1,872 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
43 2741
Cor Ligthert <no**********@p lanet.nl> wrote:
Really. Having read only Scott's post, when would you believe Foo was
eligible for garbage collection.
This is the message from Scott


<snip>

I notice you haven't answered my question.
Where Scott did write about the place it was eligible for the GC?

When the method falls out of scope, it does not always mean that an (in that
method created) object is collectable for the GC, however Scott did not
write that either.
No - but he did write "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."

To me, Scott was giving the impression that he believed that local
variables ensured that the objects they had references to were not
eligible for garbage collection until the end of a procedure. That is
not the case, as my reply said.

<snip>
And that was for me already clear in the explanation from Scott. Why would
it be set to nothing at the end of the procedure (method)


I wasn't talking about setting variables to nothing at the end of the
method. I was talking about setting variables to nothing in the
*middle* of the method, which is pointless if the variable is not used
after that point in the method anyway. That was not clear from Scott's
message.

--
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 #21
Hi Jon,

I notice you haven't answered my question.

I do not know what question however when you mean about that setting to
nothing,

When I have this

dim a as integer
a = 1
a = 2
a = 3

Where do you think a is set to 2?

So why would that be different with = nothing.
When you know how the GC works than you should know what this means. (It is
not a magical thing you know)

And to repeat, Scott only said that things can be set to nothing automaticly
when the procedure goes out of scope (and than be disposed to the GC when
there is no reference at all anymore to it, which Scott did not write).

Cor
Jul 21 '05 #22
Cor Ligthert <no**********@p lanet.nl> wrote:
I notice you haven't answered my question.
I do not know what question


The one you quoted some of but didn't answer:

<quote (from my post)>
Having read only Scott's post, when would you believe Foo was
eligible for garbage collection in the Sub below?
</quote>

(with following code, of course).

Just to clarify my meaning, I was asking when you believe the array
which the Foo variable's value was a reference to would be eligible for
garbage collection.
however when you mean about that setting to
nothing,

When I have this

dim a as integer
a = 1
a = 2
a = 3

Where do you think a is set to 2?

So why would that be different with = nothing.
Because when a is an integer, the garbage collector isn't interested in
whether or not the variable is reachable. When a is an array reference,
it is.

So, in my example, because Foo is not used after
Console.WriteLi ne(Foo(0))
it isn't considered a "root" for garbage collection (in release mode -
in debug mode this optimisation isn't performed as the developer may
want to look at its value.
When you know how the GC works than you should know what this means. (It is
not a magical thing you know)
It's certainly not a magical thing - but I think it works somewhat
differently to how you imagine it does.

I recommend the GC section of Jeffrey Richter's "Applied Microsoft .NET
framework programming" book - it's truly excellent.
And to repeat, Scott only said that things can be set to nothing
automaticly when the procedure goes out of scope (and than be
disposed to the GC when there is no reference at all anymore to it,
which Scott did not write).


Actually, Scott didn't write that, fortunately - because it's not
true.Variables aren't "set to nothing automatically" - they're just not
considered to be roots by the garbage collector any more. What Scott
*did* imply (IMO) is that local variables were always considered to be
"roots" by the garbage collector until the end of the method. That's
not true.

--
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 #23
"Erase x" is just a fancy syntax for "x = nothing". And neither of the
articles says anything about the GC, so, I really don't know what you were
trying to say?

However, I think you still didn't get Jon's point:
Take the following example:
{
TestClass x = new TestClass();
x.DoSomething() ;
GC.Collect(); // <- this will actually collect "x", although it's not
set to null!
Thread.Sleep(10 0000);
}

If you run that code, the object "x" will get collected BEFORE the sleep,
although there is still a valid reference!
The GC can tell that "x" is not used any more although there is still a
valid reference to it. It can actually "look down your code" and see if you
still use a variable or not.
So, there it's rarely usefull setting a local variable to null/nothing.

Niki

Cor Ligthert" <no**********@p lanet.nl> wrote in
news:uo******** ******@TK2MSFTN GP11.phx.gbl...
Hi Niki,

Have a look at this, and follow as well the shortlink to nothing.

http://msdn.microsoft.com/library/de...vastmerase.asp
I hope this helps?

Cor

Jul 21 '05 #24
Hi Jon,
Just to clarify my meaning, I was asking when you believe the array
which the Foo variable's value was a reference to would be eligible for
garbage collection.
I thought you did know that?
Because when a is an integer, the garbage collector isn't interested in
whether or not the variable is reachable. When a is an array reference,
it is.
Did you not know that as well?

So, in my example, because Foo is not used after
Console.WriteLi ne(Foo(0))
it isn't considered a "root" for garbage collection (in release mode -
in debug mode this optimisation isn't performed as the developer may
want to look at its value.
Why should it not be, I thought I showed you that enough I hope I made it
clear now for you?
So why would that be different with = nothing. Because when a is an integer, the garbage collector isn't interested in
whether or not the variable is reachable. When a is an array reference,
it is.
Now I see you think that the = operater is for setting objects, no it is
ment to set something, that can be 1 2 3 or nothing, depended on the kind of
receiver it acts. And when a created object has no references anymore either
way, do not make a mistake in that, (it can be also that it is referenced
itself), than it is disposable (available) to the GC.
I recommend the GC section of Jeffrey Richter's "Applied Microsoft .NET
framework programming" book - it's truly excellent.


A very good link for this to look at is.
http://msdn.microsoft.com/architectu...l/scalenet.asp
I do not agree some things in it, as by instance they write that every
control has to be disposed by hand and some other things, however for most
things it is very clear.
And to repeat, Scott only said that things can be set to nothing
automaticly when the procedure goes out of scope (and than be
disposed to the GC when there is no reference at all anymore to it,
which Scott did not write).


Actually, Scott didn't write that, fortunately - because it's not
true.Variables aren't "set to nothing automatically" - they're just not
considered to be roots by the garbage collector any more. What Scott
*did* imply (IMO) is that local variables were always considered to be
"roots" by the garbage collector until the end of the method. That's
not true.


That was the reason of my first message to you, why are you additing to
Scotts message. I nowhere readed that implyment of Scott it was only (YMO),
however had told that, than I would not have connected a message.

Cor
Jul 21 '05 #25
Hi Niki,

I did deny nothing you wrote; however, Scott did nowhere write something
else in my opinion.

However rarely set to nothing is (IMO) overdone, I never make decisions for
someone else who has cases where it is well used.

Cor

Jul 21 '05 #26
Cor Ligthert <no**********@p lanet.nl> wrote:
Just to clarify my meaning, I was asking when you believe the array
which the Foo variable's value was a reference to would be eligible for
garbage collection.


I thought you did know that?


I know when it's eligible for garbage collection. What I was asking was
when *you* believed it would be eligible for garbage collection, and
what you'd have thought just from Scott's article.
Because when a is an integer, the garbage collector isn't interested in
whether or not the variable is reachable. When a is an array reference,
it is.


Did you not know that as well?


Yes, I knew that before. It wasn't clear that you did, however.
So, in my example, because Foo is not used after
Console.WriteLi ne(Foo(0))
it isn't considered a "root" for garbage collection (in release mode -
in debug mode this optimisation isn't performed as the developer may
want to look at its value.


Why should it not be, I thought I showed you that enough I hope I made it
clear now for you?


Um, you haven't shed any light on garbage collection in this thread, as
far as I can see. What exactly do you think you've made clear, and
where?
So why would that be different with = nothing.
Because when a is an integer, the garbage collector isn't interested in
whether or not the variable is reachable. When a is an array reference,
it is.


Now I see you think that the = operater is for setting objects, no it is
ment to set something, that can be 1 2 3 or nothing, depended on the kind of
receiver it acts. And when a created object has no references anymore either
way, do not make a mistake in that, (it can be also that it is referenced
itself), than it is disposable (available) to the GC.


Not sure what you mean by "the kind of receiver it acts" but integers
themselves are never garbage collected. (Boxed versions are, of course,
but that's different.)

The = operator is for setting the value of a variable (or property),
either to a value type value or to a reference. Never to an actual
object. I think we agree on this, but I'm afraid I didn't understand
most of what you wrote above ("it can be also that it is referenced
itself" for instance)...
Actually, Scott didn't write that, fortunately - because it's not
true.Variables aren't "set to nothing automatically" - they're just not
considered to be roots by the garbage collector any more. What Scott
*did* imply (IMO) is that local variables were always considered to be
"roots" by the garbage collector until the end of the method. That's
not true.


That was the reason of my first message to you, why are you additing to
Scotts message. I nowhere readed that implyment of Scott it was only (YMO),
however had told that, than I would not have connected a message.


Scott implied it when he specified the "rather than waiting for the end
of a procedure" in my opinion. If he'd said "rather than waiting for
the last use of the variable in the IL code" then I wouldn't have
written anything. He seemed to imply that there was something special
about the end of the procedure - otherwise why mention it?

--
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 #27
"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Niki,

I did deny nothing you wrote; however, Scott did nowhere write something
else in my opinion.
Then you should probably read Scott's post.
However rarely set to nothing is (IMO) overdone,
Could you write that in an English sentence too?
I never make decisions for
someone else who has cases where it is well used.


Ok, this is really getting stupid:
The OP wanted to know how to free an array, so you can be damn sure that he
does not even know "where it is well used". That's why he asked a ng in the
first place.
So, the various posts (except yours) all included information on how arrays
(or objects in general) are freed.

That fact that you did not understand parts of that information does not
imply there is no information, you know...

Niki
Jul 21 '05 #28
Hi Nikki,
However rarely set to nothing is (IMO) overdone, Could you write that in an English sentence too?


Can you tell what it is wrong in it; I tried to understand your sentence and
gave an answer on it.However there it's rarely usefull setting a local variable to null/nothing,


Cor
Jul 21 '05 #29
Hi Jon,

Scott implied it when he specified the "rather than waiting for the end
of a procedure" in my opinion. If he'd said "rather than waiting for
the last use of the variable in the IL code" then I wouldn't have
written anything. He seemed to imply that there was something special
about the end of the procedure - otherwise why mention it?

Now I see what you do not understand, there is no need to force an array to
nothing when it is only used in a method. Then it goes automatically out of
scope as Scott stated. Only when you do not want to wait to the end of the
procedure, you have to set it to nothing. For me it was completely clear.
Sorry I did not understand that it was not for you.

I hope you have notified also my text about that this is as well only when
there are no references any more to that object.

Cor
Jul 21 '05 #30

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

Similar topics

2
26292
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
18025
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
6294
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
1958
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
1558
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
4654
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
4040
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
6533
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
10143
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
9970
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11133
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11304
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
10666
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
9866
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
4914
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
2
4515
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3516
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.