Allocate/release memory in main thread.