How would you handle memory management and prevent memory leaks when implementing quantitative models?