To enhance the solution, there should be some additional mechanism implemented that would clean unused weak pointers from time to time.
Unused weak pointers on the stack cannot be cleaned up until their lifetime ends.
A better proposal for this would be to tell programmers to be more mindful of when they let their weak pointers have unnecessarily long lifetimes, or as one of your links puts it: "So if you’re expecting to use weak_ptrs that will outlive your pointed to object and you need your memory back ASAP consider not using make_shared."
Unused weak pointers on the stack cannot be cleaned up until their lifetime ends.
A better proposal for this would be to tell programmers to be more mindful of when they let their weak pointers have unnecessarily long lifetimes, or as one of your links puts it: "So if you’re expecting to use weak_ptrs that will outlive your pointed to object and you need your memory back ASAP consider not using make_shared."
this particular quote was for this concurrent weak dictionary. So you could do an additional scan from time to tile and remove weak_pointers.