Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about ht_delete function #4

Closed
ghost opened this issue Jul 9, 2014 · 1 comment
Closed

about ht_delete function #4

ghost opened this issue Jul 9, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 9, 2014

Do I need to free key/value after call the ht_delete function?

@xant
Copy link
Owner

xant commented Jul 9, 2014

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 :

  • @note If prev_data is not NULL, the previous data will not be released using the free_value callback
  •   so the caller will be responsible of releasing the previous data once done with it
    

change the comment if you think it's not clear enough and in case I'll be happy to merge a pull request.

@xant xant closed this as completed Jul 9, 2014
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

No branches or pull requests

1 participant