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

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)
 
P

Patrice

Hello,

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

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
 
T

Tom Shelton

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.
 
J

James Hahn

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
 
P

Patrice

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 ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top