I’m having a problem where I am adding widgets to an application on the fly, but the application is crashing and eating up memory. Here’s what is happening:
I set up a callback (QNX 4.25B, Photon 1.13) in the PtTimer widget to determine the front most window (checking Ph_WM_STATE_ISFOCUS).
Then, the callback checks the local hierarchy of the window for any instances of a certain type of widget (PtLabel for example).
Anytime this widget is found, a PtPane with a Ptbutton in it is created at the same X and Y coordinates as the widget that was found. So there could be up to 20 new PtPanes created. (These are basically “balloons” that show additional information about the widget and this code is being used for testing)
The problem occurs here. Everything works fine for the startup display and the second display that I select. But after that, i get a SIGSEGV. I also notice (using “sin in”) that memory is being eaten up slowly everytime the program crashes.
Here’s the question… Is there a problem with creating widgets in this way? Am I creating multiple instances of a widget with the sample properties and causing the application to become unstable? Am I supposed to keep track of the widgets I am creating and free the pointer mem afterwards?
Any help is appreciated. Let me know if I have not been clear here.
Take a look in /dev/shmem and you will see new “files” created every time you run your app. When you crash, these “files” are not deleted (they are actually shared memory objects). You can rm them (the ones you created) to get the memory back.
Compile your program with -g and use wd on the core file after it crashes to see where/why it crashed.
I did some more digging, and it appears my crashing was a result of a couple things. One of them seemed to be initializing a static global variable to be my root widget in a PtWidgetTree call (and some other related calls). I don’t know why, but when i changed it to be a local variable it stopped crashing.
One other question. I noticed that sometimes the application is still leaving the “files” in the /dev/shmem directory. Do I need to keep track of any widgets I create in the code, and then remove them specifically when the PtWindow changes? I am not sure why these “files” are staying around, I thought anything i created would be destroyed with the window. How could I keep track of them if I needed to?