Skip to content

Conversation

@mariovisic
Copy link
Contributor

@mariovisic mariovisic commented Aug 22, 2021

After refactoring our text class to use the new texture rendering method,
changing the text means a new texture but we don't free up the old one in C
land.

When updating text we re-assign the @texture instance. Currently we
handle freeing SDL surfaces by setting the @pixel_data value to nil.
As this is a C object, the ruby garbage collector will call the correct
free function in C.

For textures though we don't hold a wrapped pointer to the C open GL
texture object, we could do, but we don't actually use it for anything
in ruby, so it would be easy to accidentally alter or remove that code
causing a memory leak. So to free up our texture we can now explicitly
call delete and pass our texture_id, this way it's obvious what that
code does and why we need it :)

After refactoring our text class to use the new texture rendering method,
changing the text means a new texture but we don't free up the old one in C
land.

When updating text we re-assign the `@texture` instance. Currently we
handle freeing SDL surfaces by setting the `@pixel_data` value to `nil`.
As this is a C object, the ruby garbage collector will call the correct
free function in C.

For textures though we don't hold a wrapped pointer to the C open GL
texture object, we could do, but we don't actually use it for anything
in ruby, so it would be easy to accidentally alter or remove that code
causing a memory leak.  So to free up our texture we can now explicitly
call delete and pass our texture_id, this way it's obvious what that
code does and why we need it :)
@mariovisic mariovisic merged commit 003ef52 into main Aug 27, 2021
@mariovisic mariovisic deleted the free_textures branch August 27, 2021 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants