-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
Looking at the Fiddle docs here: https://docs.ruby-lang.org/en/master/Fiddle/Pointer.html
We can see an example incorrect usage resulting in a memory leak:
# No free function and no call to free - the native memory will leak if the pointer is garbage collected
pointer = Fiddle::Pointer.malloc(size)
The above approach is what's used in this library, for example:
csbi = Fiddle::Pointer.malloc(24)
Correct usage, not resulting in a memory leak, taken from the Fiddle docs:
# Automatically freeing the pointer when the block is exited - recommended
Fiddle::Pointer.malloc(24, Fiddle::RUBY_FREE) do |csbi|
@GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
x,y = csbi[4,4].unpack('SS')
end
x = dpos
@SetConsoleCursorPosition.Call(@hConsoleHandle,y*65536+x)
@_rl_last_c_pos = dpos
Metadata
Metadata
Assignees
Labels
No labels