#661·mimalloc

reuse free'd memory?

Author: maartenvdCreated Dec 9, 2022Updated Sep 22, 2026
Labelsstale

I have a program that in a tight loop needs to allocate and deallocate blocks of memory (let's say of sizes (a,b,c) ), but they are the same in every iteration. I would have expected mimalloc to re-use previously allocated memory, but instead I see:

allocating Ptr{Nothing} @0x0000048b74020000
allocating Ptr{Nothing} @0x0000048b84020000
freeing Ptr{Float64} @0x0000048b84020000
allocating Ptr{Nothing} @0x0000048b94020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048bbc020000
freeing Ptr{Float64} @0x0000048bbc020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048b74020000
allocating Ptr{Nothing} @0x0000048be4020000
allocating Ptr{Nothing} @0x0000048598030500
allocating Ptr{Nothing} @0x0000048c0c020000
freeing Ptr{Float64} @0x0000048c0c020000
freeing Ptr{Float64} @0x0000048598030500
freeing Ptr{Float64} @0x0000048b94020000
allocating Ptr{Nothing} @0x0000048c34020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048c44020000
freeing Ptr{Float64} @0x0000048c44020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048be4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048c34020000
allocating Ptr{Nothing} @0x00000485984402c0
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x00000485984402c0
---
allocating Ptr{Nothing} @0x0000048c54020000
allocating Ptr{Nothing} @0x0000048c64020000
freeing Ptr{Float64} @0x0000048c64020000
allocating Ptr{Nothing} @0x0000048c74020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048c9c020000
freeing Ptr{Float64} @0x0000048c9c020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048c54020000
allocating Ptr{Nothing} @0x0000048cc4020000
allocating Ptr{Nothing} @0x0000048598030a00
allocating Ptr{Nothing} @0x0000048cec020000
freeing Ptr{Float64} @0x0000048cec020000
freeing Ptr{Float64} @0x0000048598030a00
freeing Ptr{Float64} @0x0000048c74020000
allocating Ptr{Nothing} @0x0000048d14020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048d24020000
freeing Ptr{Float64} @0x0000048d24020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048cc4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048d14020000
allocating Ptr{Nothing} @0x0000048598440300
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x0000048598440300
---
allocating Ptr{Nothing} @0x0000048d34020000
allocating Ptr{Nothing} @0x0000048d44020000
freeing Ptr{Float64} @0x0000048d44020000
allocating Ptr{Nothing} @0x0000048d54020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048d7c020000
freeing Ptr{Float64} @0x0000048d7c020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048d34020000
allocating Ptr{Nothing} @0x0000048da4020000
allocating Ptr{Nothing} @0x0000048598030a00
allocating Ptr{Nothing} @0x0000048dcc020000
freeing Ptr{Float64} @0x0000048dcc020000
freeing Ptr{Float64} @0x0000048598030a00
freeing Ptr{Float64} @0x0000048d54020000
allocating Ptr{Nothing} @0x0000048df4020000
allocating Ptr{Nothing} @0x0000048598020000
allocating Ptr{Nothing} @0x0000048e04020000
freeing Ptr{Float64} @0x0000048e04020000
freeing Ptr{Float64} @0x0000048598020000
freeing Ptr{Float64} @0x0000048da4020000
allocating Ptr{Nothing} @0x0000048598040000
freeing Ptr{Float64} @0x0000048df4020000
allocating Ptr{Nothing} @0x0000048598440380
allocating Ptr{Nothing} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598450000
freeing Ptr{Float64} @0x0000048598040000
freeing Ptr{Float64} @0x0000048598440380

So despite allocating blocks that are of the same size as very recently free'd memory, mimalloc does not reuse it. Is this expected behaviour?