optimaze alloc, free and destroy