Explicitly free byte array
-
How do i explicitly free byte array?
-
How do i explicitly free byte array?
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|
-
How do i explicitly free byte array?