added setMemoryAllocation function; leakeage memory bug fixed