Hello everyone.
I would be gratgeful for a little help if someone has the time.
My problem is that I am designing a database and one of the fields I am using is an imagegadget to hold someones photo. The problem I have is that when I move from record to record, the new photo's load in OK but it eats loads of memory because I am having to use loadimage() and pass the handle to the imagegadget. I am only using 100x100 images but I am getting a severe memory leak every time I click to view the next record.
What would be really handy for me is a solution so that I can load an image straight into an image gadget (or something similar) without having to load the image into memory first.
Has anyone got a solution for this? Or is this a case of RTFM?
Thanks, Prof.
Image gadget Problem
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Sorry, here is a little code....
I am loading a default image in here first and creating the gadget...
Here is where I am iterating through the records and loading in a new image....
It works just fine but it eats loads of memory :/
Am I doing something wrong?
Prof.
I am loading a default image in here first and creating the gadget...
Code: Select all
Photo=LoadImage(#PB_Any, "DATA\student_photos\no_photo.bmp")
Photo_Gadget=ImageGadget(#PB_Any, 350, 40, 150, 150, ImageID(Photo),#PB_Image_Border )
Code: Select all
Image_File$="DATA\Student_Photos\"+Str(Student_Record_Number)+".bmp"
Result=FileSize(Image_File$)
If Result=-1
Image_File$="DATA\student_photos\no_photo.bmp"
EndIf
Photo=LoadImage(#PB_Any, Image_File$)
SetGadgetState(Photo_Gadget, ImageID(Photo))
Am I doing something wrong?
Prof.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
When you do imageid = LoadImage(0, ...) the last image that was in image# 0 is freed each time a new one is assigned to it. With #PB_Any, this doesn't happen. Each time you assign a new image# to the variable, it is a new and different image# generated by #PB_Any, and the last one is not freed.
To solve it, do this:
and your memory leak is gone.
To solve it, do this:
Code: Select all
If IsImage(Photo)
FreeImage(Photo)
Endif
Photo = LoadImage(#PB_Any, ...)
BERESHEIT
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
One more thing I forgot to mention, you should initialize the Photo variable to -1 or something so that its initial value doesn't get shared with any existing images with static image#'s. For example, if you had an existing image 0 and the Photo variable started at 0, the first time you did the 'If IsImage' test, you would free image 0. Which presumably isn't a desired effect. If it starts at -1, it's safe to mix static image#'s with #PB_Any's.
BERESHEIT
