Closed ghost closed 10 years ago
keys are always copied internally (because growing the table would need to relocate them and anyway you don't want a key do be modifiable once stored in the hashtable) ... so you need to free you key (if alloc'd on the heap) when you don't need it anymore.
The value needs to be freed only if you are collecting it by passing a reference to the 'void **prev_data' argument (where to store the pointer to the value) If you pass NULL the value will be freed using the callback provided at construction time.
Note that if you didn't provide any callback the value will be leaked .... you can also just pass 'free' as callback.
In the documentation for the function (hashtable.h) I see :
change the comment if you think it's not clear enough and in case I'll be happy to merge a pull request.
Do I need to free key/value after call the ht_delete function?