DestroyObject(object);
there is no function to "detach" attached objects.
You could make one though
btw. you should make the variable holding the id of your object globally accessible
to be able to use it in different commands. like one to create the object and one to remove the object