microsoft / microsoft/mimalloc
Memory leak when statically linked mimalloc to a dll, which is unloaded via a non main thread
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
In this case the dll(statically linked mimalloc) is loaded by the main thread. But then it is unloaded by another worker thread. In this case the memory allocated in the arena is not freed.
These two blocks does not get called in heap.c
heap.c. Leaks arena
if (collect >= MI_FORCE && _mi_is_main_thread() && mi_heap_is_backing(heap)) {
_mi_mem_collect(&heap->tld->os);
}
heap.c . Not sure if this adds to leak.
if (
#ifdef NDEBUG
collect == MI_FORCE
#else
collect >= MI_FORCE
#endif
&& _mi_is_main_thread() && mi_heap_is_backing(heap) && !heap->no_reclaim)
{
// the main thread is abandoned (end-of-program), try to reclaim all abandoned segments.
// if all memory is freed by now, all segments should be freed.
_mi_abandoned_reclaim_all(heap, &heap->tld->segments);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in heap.c and reproduce unloading a DLL with statically linked mimalloc from a worker thread after it was loaded by the main thread. Trace the conditions around _mi_mem_collect and _mi_abandoned_reclaim_all, then verify that the arena memory is reclaimed when the DLL is unloaded outside the main thread.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100