Skip to content
instance method

IO::Buffer#free

() -> self
free → self

If the buffer references memory, release it back to the operating system.

  • for a mapped buffer (e.g. from file): unmap.

  • for a buffer created from scratch: free memory.

  • for a buffer created from string: undo the association.

After the buffer is freed, no further operations can’t be performed on it.

You can resize a freed buffer to re-allocate it.

Example
buffer = IO::Buffer.for('test')
buffer.free
# => #<IO::Buffer 0x0000000000000000+0 NULL>

buffer.get_value(:U8, 0)
# in `get_value': The buffer is not allocated! (IO::Buffer::AllocationError)

buffer.get_string
# in `get_string': The buffer is not allocated! (IO::Buffer::AllocationError)

buffer.null?
# => true
See also #external? #get_string #empty? #get_value also in 3.4 · 3.3 · 3.2 · 3.1