wide use of the setMemoryAllocation function; leakeage memory bug fixed