Release memory used from a buffer

  • Thread starter Thread starter NetMasker
  • Start date Start date
N

NetMasker

I used the following command to keep ~50Mbytes for a buffer:

Dim inBuf(50000000) As Byte

I used the buffer and now I want to release the 50Mbytes of memory that my
buffer used.
Is there any way to clear the buffer ???

I tried with the following but nothing happend:
Array.Clear(inBuf, 0, 50000000)
inBuf = Nothing

Thanks in advance
 
It's all about the garbage collector: The CLR releases object memory on a
low priority thread, or when it detects the system needs resources.

Just have patience and the memory will be recovered.

Of course if you're like me and you have very little patience, you can call
System.GC.Collect() which will force the garbage collection, although you'll
take a performance hit.


Regards,

Ben
 
NetMasker,

Althouhg you can call the GC, does that mean probably only some nanoseconds
and an not wanted performance hit on your program.

An object is released from memory when there is not anymore a reference to
it, or from it, in your case only to it.

Than is important the place where it is created (the place where the address
is)
The queckest it is released in the lowest place of a routine.

\\\
For i as as integer = 0 to 10
dim sb as new stringbuilder()
Next
///
here all the stringbuilder will be quickly released
\\\
Public class mymodule
Public shared sb as stringbuilder
End class
For i as integer = 0 to 10
sb = new stringbuilder()
Next
///
Here at least the last sb stays in memory until the end, while the GC has
more problems with releasing this kind of constructions.

I hope this gives some ideas

Cor
 

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

Back
Top