07-10-2003, 05:20 AM
I'm an using one picturebox on a form and want to load about 100 pictures individually into it at the user's command. I am using the LoadPicture function to do this. What can I do to avoid memory problems? (Or will I have any?) Would LoadPicture(nullstring) release memory? Or is there another way to release the memory taken by the picturebox?
07-10-2003, 05:39 AM
Well, if you are only using one picture, then that's the only thing that should be in the picturebox memory is one picture :).
(and the other picturebox stuff)
07-10-2003, 07:56 AM
The picturebox is a heavy weight control and uses a lot of memory. Actually the gdi creates a second instance of the graphic.
Set Picture1.picture = Nothing
will release the memory of the control.
If you need to load a load of images into memory and be conservative of memory, then load them into a lightweight control such as the image control. You just transfer the graphic into a picturebox if and when you need to perform some graphic operation on it requiring access to its hdc using api operations.
Now like mentioned above, if you are only using the one picturebox control then their is not a memory management problem. But what are you doing with these images? If you are placing these images elsewhere such on another heavyweight control, then there is the memory problem. If you are loading the images in a directory, then performing some gdi operation on them (such as creating thumbnails of the images) and saving the result of this operation then loading the next graphic, then NO PROBLEM!
07-11-2003, 05:12 AM
The only way not to use a lot of memory is to load it part by part everytime you need it and do something with it. In this case it would meen to load each picture separately, paint it on the form and then unload it and load another picture and so on, so there will always be just one picture in the memory at the time.
It is quite clear that there are just two options:
1. use lots of memory while performance is faster
2. use a little memory while performance is slower
I mean....loading every picture and painting it on the form everytime the form needs to be repainted is certainly much slower than just filling 100 picture boxes with pictures and using lots of memory.
It's just a matter of decision...however, it is strongly recommended to check for free memory if you're going to use lots of it.