How would you optimize memory usage and avoid leaks when handling large cryptographic keys or image assets in a native mobile application?