I guess you need to use:
ptr_remove(void* object);
Because the way you create the pan like this, in run-time can be deleted only this way (or only after turning engine off, as manual says). But I advice you not to create panel at run-time, but to create it at the beginning on your script, and make it invisible, so then you'll be able to toggle visibility on and off.