I don’t fully understand why c functions have a fr...
# kotlin-native
s
I don’t fully understand why c functions have a free method for every single struct type. Wouldn’t a general purpose
free
method work, or heck, just using the C free method itself.
m
Usually they do more than allocating a single struct. ffmpeg has its own memory management stuff that I can't remember because it's been a long time but automatically frees some other structs/file descriptors that could have been open during the lifetime of the "object/struct"
s
so I should probably rely on the free function, not the memScoped function?
m
If you're using some library that has its own
foo_free()
, yes, most likely
Unless memScope {} could intercept the underlying
malloc()
calls (from inside the lib)?
But that seems unlikely + it wouldn't handle stuff like file descriptors
s
👍 Thanks