Hi ,
i would like to get some explanation about using the Obj = Nothing .
For example ,
I have a function that hold a local object like in this example
public function Test()
dim objMyCol as New Collection()
some code here ....
objMyCol = Nothing ' do i need this line ?
end function
should i use the objMyCol = Nothing before exiting the function Or it will
be set to nothing automatically when the function end ?
one more example ,
I have a class and i have in that class few public/private/shared objects
which are used all over the class .
do i need to close and to set the objects to nothing in the Finalize method
or they will be close and set to nothing automatically ?
does the garbage collector responsible for cleaning unclosed or unused
objects ?
10x in Advanced
Best Regards ,
Tiraman ;-) 8 1612
"Tiraman" <ti*****@netvision.net.il> schrieb Hi ,
i would like to get some explanation about using the Obj = Nothing .
For example , I have a function that hold a local object like in this example
public function Test() dim objMyCol as New Collection()
some code here ....
objMyCol = Nothing ' do i need this line ? end function
should i use the objMyCol = Nothing before exiting the function
No
Or it will be set to nothing automatically when the function end ?
When the function ends there is nothing that can be set to Nothing because
the variable is destroyed. Cleaning a house that will be destroyed doesn't
make sense. ;-)
one more example ,
I have a class and i have in that class few public/private/shared objects which are used all over the class .
do i need to close and to set the objects to nothing in the Finalize method or they will be close and set to nothing automatically ?
No, for the same reason as above: when the object is destroyed, it is
detroyed. It doesn't matter whether a field containing Nothing or anything
else is destroyed.
does the garbage collector responsible for cleaning unclosed or unused objects ?
Yes, it is. The GC collects all unused objects. Don't know what "unclosed"
means. If managed objects use unmanaged resources, the resources must also
be freed before the managed resources are collected and finalized. Each
object must give these resources free before it get's finalized. In
addition, those objects usually have a Dispose method in order to give the
resources free earlier, i.e. before the GC will collect the object.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
so when we should use the obj = nothing ?
10x
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de... "Tiraman" <ti*****@netvision.net.il> schrieb Hi ,
i would like to get some explanation about using the Obj = Nothing .
For example , I have a function that hold a local object like in this example
public function Test() dim objMyCol as New Collection()
some code here ....
objMyCol = Nothing ' do i need this line ? end function
should i use the objMyCol = Nothing before exiting the function
No
Or it will be set to nothing automatically when the function end ?
When the function ends there is nothing that can be set to Nothing because the variable is destroyed. Cleaning a house that will be destroyed doesn't make sense. ;-)
one more example ,
I have a class and i have in that class few public/private/shared objects which are used all over the class .
do i need to close and to set the objects to nothing in the Finalize method or they will be close and set to nothing automatically ?
No, for the same reason as above: when the object is destroyed, it is detroyed. It doesn't matter whether a field containing Nothing or anything else is destroyed.
does the garbage collector responsible for cleaning unclosed or unused objects ?
Yes, it is. The GC collects all unused objects. Don't know what "unclosed" means. If managed objects use unmanaged resources, the resources must also be freed before the managed resources are collected and finalized. Each object must give these resources free before it get's finalized. In addition, those objects usually have a Dispose method in order to give the resources free earlier, i.e. before the GC will collect the object.
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
> so when we should use the obj = nothing ?
I see this as a question on that very good explanation from Armin.
When it was not meant as that than sorry for my response.
I think a good place is after me.close in the main thread, you are than sure
that it does nothing.
It only makes your program than a very little bit bigger.
:-)
Cor
10x :-)
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:#v**************@tk2msftngp13.phx.gbl... so when we should use the obj = nothing ? I see this as a question on that very good explanation from Armin. When it was not meant as that than sorry for my response.
I think a good place is after me.close in the main thread, you are than
sure that it does nothing.
It only makes your program than a very little bit bigger.
:-)
Cor
"Cor Ligthert" <no**********@planet.nl> schrieb so when we should use the obj = nothing ? I see this as a question on that very good explanation from Armin.
Thanks, Cor. :-)
When it was not meant as that than sorry for my response.
No, it was not meant as a good explanation.... ;-)
I think a good place is after me.close in the main thread, you are than sure that it does nothing.
It only makes your program than a very little bit bigger.
:-)
:)
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Tiraman,
Armin did a good job of explaining setting objects to nothing. so when we should use the obj = nothing ?
I primarily use obj = nothing, when I have a persistent (reachable)
variable, that has a reference to an object that is no longer needed. For
example I have a shared field that points to a form, in the close for the
form, I will set the shared field to nothing, as the form is going away.
I will occasionally use obj = nothing, when I am in the middle of a routine
and I want to be certain that I do not reuse an object in a local variable.
However this is rare.
Hope this helps
Jay
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl... so when we should use the obj = nothing ?
10x "Armin Zingler" <az*******@freenet.de> wrote in message news:40***********************@news.freenet.de... "Tiraman" <ti*****@netvision.net.il> schrieb Hi ,
i would like to get some explanation about using the Obj = Nothing .
For example , I have a function that hold a local object like in this example
public function Test() dim objMyCol as New Collection()
some code here ....
objMyCol = Nothing ' do i need this line ? end function
should i use the objMyCol = Nothing before exiting the function
No
Or it will be set to nothing automatically when the function end ?
When the function ends there is nothing that can be set to Nothing
because the variable is destroyed. Cleaning a house that will be destroyed
doesn't make sense. ;-)
one more example ,
I have a class and i have in that class few public/private/shared objects which are used all over the class .
do i need to close and to set the objects to nothing in the Finalize method or they will be close and set to nothing automatically ?
No, for the same reason as above: when the object is destroyed, it is detroyed. It doesn't matter whether a field containing Nothing or
anything else is destroyed.
does the garbage collector responsible for cleaning unclosed or unused objects ?
Yes, it is. The GC collects all unused objects. Don't know what
"unclosed" means. If managed objects use unmanaged resources, the resources must
also be freed before the managed resources are collected and finalized. Each object must give these resources free before it get's finalized. In addition, those objects usually have a Dispose method in order to give
the resources free earlier, i.e. before the GC will collect the object.
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
10x
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl... Tiraman, Armin did a good job of explaining setting objects to nothing.
so when we should use the obj = nothing ? I primarily use obj = nothing, when I have a persistent (reachable) variable, that has a reference to an object that is no longer needed. For example I have a shared field that points to a form, in the close for the form, I will set the shared field to nothing, as the form is going away.
I will occasionally use obj = nothing, when I am in the middle of a
routine and I want to be certain that I do not reuse an object in a local
variable. However this is rare.
Hope this helps Jay
"Tiraman" <ti*****@netvision.net.il> wrote in message news:Ov**************@tk2msftngp13.phx.gbl... so when we should use the obj = nothing ?
10x "Armin Zingler" <az*******@freenet.de> wrote in message news:40***********************@news.freenet.de... "Tiraman" <ti*****@netvision.net.il> schrieb > Hi , > > i would like to get some explanation about using the Obj = Nothing > . > > For example , > I have a function that hold a local object like in this example > > public function Test() > dim objMyCol as New Collection() > > some code here .... > > objMyCol = Nothing ' do i need this line ? > end function > > should i use the objMyCol = Nothing before exiting the function
No
> Or > it will be set to nothing automatically when the function end ?
When the function ends there is nothing that can be set to Nothing because the variable is destroyed. Cleaning a house that will be destroyed doesn't make sense. ;-)
> one more example , > > I have a class and i have in that class few public/private/shared > objects which are used all over the class . > > do i need to close and to set the objects to nothing in the Finalize > method or they will be close and set to nothing automatically ?
No, for the same reason as above: when the object is destroyed, it is detroyed. It doesn't matter whether a field containing Nothing or anything else is destroyed.
> does the garbage collector responsible for cleaning unclosed or > unused objects ?
Yes, it is. The GC collects all unused objects. Don't know what "unclosed" means. If managed objects use unmanaged resources, the resources must also be freed before the managed resources are collected and finalized.
Each object must give these resources free before it get's finalized. In addition, those objects usually have a Dispose method in order to give the resources free earlier, i.e. before the GC will collect the object.
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Thanks !
Tiraman ;-)
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl... Tiraman, Armin did a good job of explaining setting objects to nothing.
so when we should use the obj = nothing ? I primarily use obj = nothing, when I have a persistent (reachable) variable, that has a reference to an object that is no longer needed. For example I have a shared field that points to a form, in the close for the form, I will set the shared field to nothing, as the form is going away.
I will occasionally use obj = nothing, when I am in the middle of a
routine and I want to be certain that I do not reuse an object in a local
variable. However this is rare.
Hope this helps Jay
"Tiraman" <ti*****@netvision.net.il> wrote in message news:Ov**************@tk2msftngp13.phx.gbl... so when we should use the obj = nothing ?
10x "Armin Zingler" <az*******@freenet.de> wrote in message news:40***********************@news.freenet.de... "Tiraman" <ti*****@netvision.net.il> schrieb > Hi , > > i would like to get some explanation about using the Obj = Nothing > . > > For example , > I have a function that hold a local object like in this example > > public function Test() > dim objMyCol as New Collection() > > some code here .... > > objMyCol = Nothing ' do i need this line ? > end function > > should i use the objMyCol = Nothing before exiting the function
No
> Or > it will be set to nothing automatically when the function end ?
When the function ends there is nothing that can be set to Nothing because the variable is destroyed. Cleaning a house that will be destroyed doesn't make sense. ;-)
> one more example , > > I have a class and i have in that class few public/private/shared > objects which are used all over the class . > > do i need to close and to set the objects to nothing in the Finalize > method or they will be close and set to nothing automatically ?
No, for the same reason as above: when the object is destroyed, it is detroyed. It doesn't matter whether a field containing Nothing or anything else is destroyed.
> does the garbage collector responsible for cleaning unclosed or > unused objects ?
Yes, it is. The GC collects all unused objects. Don't know what "unclosed" means. If managed objects use unmanaged resources, the resources must also be freed before the managed resources are collected and finalized.
Each object must give these resources free before it get's finalized. In addition, those objects usually have a Dispose method in order to give the resources free earlier, i.e. before the GC will collect the object.
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BadPony |
last post by:
Anyone using Peoplesoft on a Federated UDB
(shared nothing)Environment on Open System Platforms?
Preferably AIX, but any war stories would be good.
TEA
EB-C
|
by: Hardy |
last post by:
I'm pretty new in this field. when reading some 70x material, I met with
this term but cannot catch its accurate meaning. who can help me? thanks in
advance:)~
|
by: Bob Day |
last post by:
VS 2003
The documentation says " Nothing keyword represents the default value of any
data type" this is simply not true and causing a lot of problems.
1) Consider an SQL table of 3 columns:
...
|
by: Bob Day |
last post by:
VS 2003, vb.net, sql native (MSDE)...
I have railed against the inconsistency of the Nothing key word. The
documentation says is will assign a default value for any datatype...well,
not...
|
by: David Schwartz |
last post by:
Seems that setting an object = Nothing no longer does anything in .NET.
Garbage collection destroys the object eventually. So, does it ever make
sense to set an object = Nothing in .NET?
Thanks.
|
by: John A Grandy |
last post by:
do these mean the same thing ?
Dim s As String
.....
If s Is Nothing Then
.....
If s = Nothing Then
.....
|
by: Mike Eaton |
last post by:
Hi all,
What do people regard as the best practice with respect to freeing object references when you're done with them? Some people I've worked with in the past suggested that if you create an...
|
by: Doug Glancy |
last post by:
I got the following code from Francesco Balena's site, for disposing of Com
objects:
Sub SetNothing(Of T)(ByRef obj As T)
' Dispose of the object if possible
If obj IsNot Nothing AndAlso...
|
by: DippyDog |
last post by:
This is an old old post that I'm referencing regarding what happens
when you set an integer variable to Nothing. It gets set to zero, not
"Nothing."
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |