Page 1 of 1
When should you run CPhidget_delete?
Posted: Sat Nov 04, 2017 8:49 pm
by gusdsnail
Hi,
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?
Cheers,
Ed
Re: When should you run CPhidget_delete?
Posted: Mon Nov 06, 2017 11:28 am
by mparadis
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?
Re: When should you run CPhidget_delete?
Posted: Tue Nov 07, 2017 7:38 pm
by gusdsnail
I'm running Phidget21. I'm not ready yet to upgrade to Phidget22.
Yes I understand the memory issue. I'm trying to make sure there aren't any memory issues. I suppose I'm curious to know what the proper lifecycle is.
On windows it seems executing CPhidget_delete in the detach event is a problem. When is it safe to execute CPhidget_delete?
Thanks for your help
Re: When should you run CPhidget_delete?
Posted: Wed Nov 08, 2017 3:46 pm
by mparadis
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.