Release memory used from a buffer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NetMasker

    #1

    Release memory used from a buffer

    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(inB uf, 0, 50000000)
    inBuf = Nothing

    Thanks in advance


  • Benjamin Pierce

    #2
    Re: Release memory used from a buffer

    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.Colle ct() which will force the garbage collection, although you'll
    take a performance hit.


    Regards,

    Ben

    "NetMasker" <netmasker@yaho o.com> wrote in message
    news:O%23z3yIKY FHA.3184@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    > 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(inB uf, 0, 50000000)
    > inBuf = Nothing
    >
    > Thanks in advance
    >
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: Release memory used from a buffer

      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


      Comment

      Working...