Describe how you would handle memory management and prevent memory leaks in a long-running Node.js or Python application.