End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO::Buffer#free
free → self
io_buffer.c
View on GitHub ↗
VALUE
rb_io_buffer_free(VALUE self)
{
struct rb_io_buffer *data = NULL;
TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
if (data->flags & RB_IO_BUFFER_LOCKED) {
rb_raise(rb_eIOBufferLockedError, "Buffer is locked!");
}
io_buffer_free(data);
return 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:
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