hraban / opus

Go wrapper for libopus (golang)
MIT License
267 stars 57 forks source link

How to destroy en(de)coder state? #42

Closed tj10200 closed 2 years ago

tj10200 commented 2 years ago

There doesn't appear to be a binding for opus_encoder_destroy or the decoder equivalent. If I understand the docs correctly this indicates that the opus state object leaks memory each time an instance is created.

Or is there something hidden that I may have missed?

hraban commented 2 years ago

opus_encoder_destroy is only for apps which use opus_encoder_create. This lib instead uses opus_encoder_init. From the docs:

Initializes a previously allocated encoder state The memory pointed to by st must be at least the size returned by opus_encoder_get_size().

This is intended for applications which use their own allocator instead of malloc.

https://opus-codec.org/docs/opus_api-1.3.1/group__opus__encoder.html#ga515db1c267a7421dacaad3610f79eb79

This wrapper uses Go's make([]byte, ...) to allocate memory, so freeing the encoder is a matter of letting it get garbage collected.

Closing the issue but feel free to reopen / continue discussion if there's any further concerns.

tj10200 commented 2 years ago

Nope that's great, I did misunderstand. Glad I asked, and thanks so much for getting around to it so quickly.