.NET Framework - Can we "dispose" an array? (VB 2008)

Asked By sam on 28-Aug-09 12:39 PM
Hi,
I write some of the code that work with big array.  Is there any way
that I can dispose an array?
Example
Dim myArray() as integer
myArray=Big Array
Dim otherArray() as integer
otherArray=Other Big Array
myArray=otherArray

I know that the Big Array that was referred by myArray will be reclaimed
by Garbage Collection.  But, can I "dispose" it like we do with an object?
TIA
Sam (Please pardon my English)




Patrice replied on 28-Aug-09 12:55 PM
Hello,

Dispose is to release unmanaged resources. What is the problem you are
trying to solve ?

--
Patrice
sam replied on 28-Aug-09 01:34 PM
Well, not exactly a problem. I feel that since it is a good idea (as I
understand it) to release the resources using by an object by disposing
it after we done with it. And an array (big one) use a lot of memory
should not we do the same thing?
TIA
Sam
Tom Shelton replied on 28-Aug-09 01:51 PM
No.  Dispose is a pattern that is mainly there to handle situations where your
class is dealing with unmanaged resources (such as window handles, db
connections, sockets, etc.).

The memory allocated by the runtime for the array is better left to the gc to
handle.

--
Tom Shelton
Herfried K. Wagner [MVP] replied on 28-Aug-09 01:56 PM
This is not necessarily the case, although it is often used for this
purpose.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
James Hahn replied on 29-Aug-09 02:05 AM
If BigArray does not immediately go out of scope for some reason, then you
can reclaim the memory that it is using with

BigArray = Nothing
Patrice replied on 29-Aug-09 05:16 AM
The idea behind the GC is that there is no point in cleanup up the memory if
you do not need this memory right now (plus the memory could be reused by
something else in your code rather than being released to the OS and then
reclaimed again few lines later).

So if you do not have a reference (either because it goes out of scope or
because you set explicitely the array to null) to the array, the GC should
do its job when it feels it should ;-)

--
Patrice