Cleaning up memory by removing elements that are no longer visible.