Accord.Imaging.MemoryManager.Free C# (CSharp) Method

Free() public static method

Free unmanaged memory.
This method may skip actual deallocation of memory and keep it for future Alloc requests, if some caching scheme is used.
public static Free ( IntPtr pointer ) : void
pointer System.IntPtr Pointer to memory buffer to free.
return void
        public static void Free( IntPtr pointer )
        {
            lock ( memoryBlocks )
            {
                // find the memory block in cache
                for ( int i = 0; i < currentCacheSize; i++ )
                {
                    if ( memoryBlocks[i].MemoryBlock == pointer )
                    {
                        // mark the block as free
                        memoryBlocks[i].Free = true;
                        busyBlocks--;
                        return;
                    }
                }

                // the block was not cached, so lets just free it
                Marshal.FreeHGlobal( pointer );
            }
        }