faster memory management for stacks and trees