Added memory management function.