Tracking nesting depth to allow efficient array slicing, with no memory leaks and logarithmic slicing costs.