Gadgets and FreeGadget
Gadgets and FreeGadget
Gadgets and FreeGadget
Hello everyone,
I would like to have your opinion on a question that I ask myself. For this, I will take an example to explain myself. It is just an example, it has nothing to do with what I want to do.
Let's imagine that I write a program, with on the left of the screen, several buttons. A "Trees" button, an "Animals" button, a "Fruits" button, etc...
By clicking, for example, on the "Trees" button, I display pictures of trees in ImageGadget(), there is a quantity that I do not know.
Likewise, if I click on the "Animals" button, I display pictures of animals in ImageGadget().
My idea is to dynamically create the ImageGadet() each time and then free them (Freegadget()).
The question I ask myself is this.
Doesn't creating and freeing (FreeGadget()) risk saturating the computer's memory after a while?
Hello everyone,
I would like to have your opinion on a question that I ask myself. For this, I will take an example to explain myself. It is just an example, it has nothing to do with what I want to do.
Let's imagine that I write a program, with on the left of the screen, several buttons. A "Trees" button, an "Animals" button, a "Fruits" button, etc...
By clicking, for example, on the "Trees" button, I display pictures of trees in ImageGadget(), there is a quantity that I do not know.
Likewise, if I click on the "Animals" button, I display pictures of animals in ImageGadget().
My idea is to dynamically create the ImageGadet() each time and then free them (Freegadget()).
The question I ask myself is this.
Doesn't creating and freeing (FreeGadget()) risk saturating the computer's memory after a while?
Re: Gadgets and FreeGadget
No, it shouldn't.
Re: Gadgets and FreeGadget
Create an ImageGadget and use SetGadgetState() to add a new image every time.
This way you do not need to create a new gadget for each image. Use dynamically
created images (or load them with #PB_Any as number) and release them after use.
That would be the normal procedure.
And to the main question:
No, it should have no effect on the total memory of the computer.
The operating system should take care of these things.
Unless you forget to free something
This way you do not need to create a new gadget for each image. Use dynamically
created images (or load them with #PB_Any as number) and release them after use.
That would be the normal procedure.
And to the main question:
No, it should have no effect on the total memory of the computer.
The operating system should take care of these things.
Unless you forget to free something
Re: Gadgets and FreeGadget
Hello Fred and Bisonte,
Thanks for your answers.
To answer Bisonte, of course, I can create the gadgets and reuse them with SetGadgetState(), but I don't know the number of images to display, so I would have to create a certain number of ImageGadget without being sure to have created enough.
Thanks for your answers.
To answer Bisonte, of course, I can create the gadgets and reuse them with SetGadgetState(), but I don't know the number of images to display, so I would have to create a certain number of ImageGadget without being sure to have created enough.
Re: Gadgets and FreeGadget
No; in fact that's the total opposite. Freeing it before recreating is the best way to not saturate your PC's memory.jak64 wrote: Mon Mar 10, 2025 11:06 amDoesn't creating and freeing (FreeGadget()) risk saturating the computer's memory after a while?
Fun Fact: You don't even need to free a gadget if you recreate it with the same gadget number, because PureBasic will free it automatically.
Re: Gadgets and FreeGadget
Hello BarryG
Thanks, I didn't know that recreating it with the same number automatically frees it, but in my case I create them with #pb_Any, and as I mentioned, I don't know the number to create (100, 200, 500, 1000?)
Thanks, I didn't know that recreating it with the same number automatically frees it, but in my case I create them with #pb_Any, and as I mentioned, I don't know the number to create (100, 200, 500, 1000?)
Re: Gadgets and FreeGadget
With #PB_Any you must explicitly call FreeGadget.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Gadgets and FreeGadget
thanks mk-soft
Re: Gadgets and FreeGadget
Alternatively, create a CanvasGadget yourself and draw a grid with the images.
Display the CanvasGadget in the size of the window and mathematically redraw only the images that fit into the window.
Display the CanvasGadget in the size of the window and mathematically redraw only the images that fit into the window.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Gadgets and FreeGadget
Hello mk-soft,
I opted for a scrollarea in which I add as many gadgets as necessary and it works very well like that.
However, I just made another post, because I noticed that, if we use a scrollarea in which we put canvasgadgets, then the mouse wheel does not work to scroll vertically!
I opted for a scrollarea in which I add as many gadgets as necessary and it works very well like that.
However, I just made another post, because I noticed that, if we use a scrollarea in which we put canvasgadgets, then the mouse wheel does not work to scroll vertically!
Re: Gadgets and FreeGadget
@jak64,
As I showed in the other post, the behavior is logical and understandable, because both gadgets can receive the mouse wheel event.
As I showed in the other post, the behavior is logical and understandable, because both gadgets can receive the mouse wheel event.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Gadgets and FreeGadget
OK, Thanks Axolotl



