Can we "dispose" an array? (VB 2008)

  • Thread starter Thread starter sam
  • Start date Start date
S

sam

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)
 
Hello,

Dispose is to release unmanaged resources. What is the problem you are
trying to solve ?
 
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
shouldn't we do the same thing?
TIA
Sam
 
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
shouldn't we do the same thing?
TIA
Sam

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.
 
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
 
The idea behind the GC is that there is no point in cleanup up the memory if
you don't 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 don't 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 ;-)
 
Back
Top