diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 8ae9542c2c2f4..b775bc88d1bb0 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -547,9 +547,13 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI end end function cleanup!(node::StackFrameTree) - empty!(node.builder_key) - empty!(node.builder_value) - foreach(cleanup!, values(node.down)) + stack = StackFrameTree[node] + while !isempty(stack) + node = pop!(stack) + empty!(node.builder_key) + empty!(node.builder_value) + append!(stack, values(node.down)) + end nothing end cleanup!(root)