When should you run CPhidget_delete?

C, C++, and Visual C++
Post Reply
gusdsnail
Phidgetsian
Posts: 11
Joined: Thu Aug 01, 2013 6:29 am
Contact:

When should you run CPhidget_delete?

Post 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
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: When should you run CPhidget_delete?

Post 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?
gusdsnail
Phidgetsian
Posts: 11
Joined: Thu Aug 01, 2013 6:29 am
Contact:

Re: When should you run CPhidget_delete?

Post 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
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: When should you run CPhidget_delete?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests