While porting over to windows from mac, my app was crashing. I isolated the problem to `CPhidget_delete`. I was running the `CPhidget_delete` as clean up on sensor detach event. This was not an issue on mac.
This begs the question. When should you run `CPhdiget_delete`? Only on exit?
The "delete" function frees up the memory space that was used up by creating the Phidget object. This is essential for long-running programs that create a lot of Phidget handles, since the computer would eventually run out of memory if unused objects weren't deleted. As for why it's crashing, it's possible there's a weird interaction from having it in the detach handler. Are you using Phidget21 or Phidget22?
It should be safe to run CPhidget_delete any time after closing. The problem here is that the object probably is still in use during the detach handler.
If your program is expecting to connect to a lot of different Phidgets, you can try using the Phidget Manager to attach and detach the Phidgets. You should be able to safely call delete in the Manager detach event. If you're only ever expecting to be connected to one Phidget of that type at any given time, then you can safely reuse the handle since you don't have to worry about them piling up over time.
The other option is to upgrade to Phidget22 which handles this issue.