Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Explicitly free byte array

Explicitly free byte array

Scheduled Pinned Locked Moved C#
questiondata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dudi Avramov
    wrote on last edited by
    #1

    How do i explicitly free byte array?

    L L 2 Replies Last reply
    0
    • D Dudi Avramov

      How do i explicitly free byte array?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, when the last reference to an object (such as a byte array) is given up, the object becomes collectable. Examples:

      {
      ...
      byte[] myArray=new byte[1000];
      ...
      myArray=new byte[2000]; // old array is abandoned
      ...
      myArray=null; // second array is abandoned
      ...
      myArray=new byte[3000];
      ...
      } // third array is abandoned (myArray out of scope)

      Collectable means the garbage collector, when it decides to run, would find and collect the object. However it will only run when there is a need to run, unless you force it with one of the GC methods. Doing so is almost always a bad idea, since a GC run is costly, and temporarily blocks all the threads; therefore the GC should only run when necessary, i.e. when there isn't enough free memory to satisfy a new SomeThing() request. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Voting for dummies? No thanks. X|


      1 Reply Last reply
      0
      • D Dudi Avramov

        How do i explicitly free byte array?

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Hopefully you are asking about what Luc posted, setting the variable to null. Otherwise you are out of luck since finalization is non-deterministic in the Garbage Collected environment.

        led mike

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups