added freeMemory() function