Added generic functions for memory management.