Simple-Sparsehash icon indicating copy to clipboard operation
Simple-Sparsehash copied to clipboard

Memory leak in sparse_dict_free

Open je-so opened this issue 9 years ago • 1 comments

You forgot to free copied keys and values.

Also: Allocating every single value is slow. Instead allocate a single big memory pages and allocate keys,values at the end of the used space. If you manage the memory pages in a list then you should free every single page of this list in sparse_dict_free to prevent a memory leak.

Hint: If you develop on Linux with gcc you could use malloc_stats() to print the memory in use!

je-so avatar Jun 14 '15 06:06 je-so

So instead of storing copied keys and values on the heap individually and storing pointers on struct sparse_bucket objects I'd store them into individual lists on the struct sparse_dict object and reference them via offsets into this big list (or lists) of pages? Replacing/deleting buckets could get tricky then, I'd end up having chunks of unused space that I would have to deal with. I think I'm gonna wait until I'm back home before I start working on this one, my usage of malloc() is definitely the bottleneck right now.

Also I didn't know about malloc_stats(), thats really useful.

qpfiffer avatar Jun 14 '15 13:06 qpfiffer