instance method
IO::Buffer#free
() -> self
free → self
io_buffer.c
View on GitHub ↗
VALUE
rb_io_buffer_free(VALUE self)
{
struct rb_io_buffer *buffer = NULL;
TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, buffer);
if (buffer->flags & RB_IO_BUFFER_LOCKED) {
rb_raise(rb_eIOBufferLockedError, "Buffer is locked!");
}
io_buffer_free(buffer);
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
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