You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In configuration a free function specifically to free keys in hashtable_remove and hashtable_destroy cases can be added. In current configuration the keys are left in heap if they were dynamically allocated.
The text was updated successfully, but these errors were encountered:
If I understand you correctly, you're saying that there should be a pointer to a free function kept in the hashtable structure that would be used to automatically free data when it's removed from the table?
If that's the case, I think it is probably a good idea to add an option for that. Although I think it might be better to do it with a callback function instead of adding another field to the structure. You might want to take a look at this related issue.
Thanks for the answer.
I needed a solution immediately so I added 2 function pointers to both struct hashtable_s and hashtable_conf_s:
table->key_free
table->value_free
By default NULL is assigned to both of these functions (to match the current configuration) and before calling I always check to make sure they are not NULL: like in hashtable_remove function:
if(table->key_free != NULL)
table->key_free(key);
The text was updated successfully, but these errors were encountered: