Hi, I would like to know how to free a memory after I am using a imagelist or picturebox/ image file.

I have a program who loads picturebox into a imagelist, only 2 pictures at the time.

My problem is, after running my program several times (by using "start" command in vb6)... maybe around 100 times or so... I have got out of memory error.
I assume it is linked to the memory that I didn't free up when I close a program. how do I free that memory?


8 Years
Discussion Span
Last Post by neosonic

The mere fact that you ran out of memory will obviously be the capacity of your pc. Always remember that other people might have a system slower or smaller than yours, thus you need to ensure to make your application as bug free and fast as possible.

Getting to your question, why would you want to open your application so many times? When opening your application, see if another instance of it is already running or not by using the following -

If App.PrevInstance = True Then
End If

When you are running your application, ensure that when a user is done with a form, close it. You will run out of memory if too many forms are open, especially in a large application. Remember that when you open a form, all of it is loaded to memory, thus failing when too many open. Close a form like -


I hope this answers your question for you...


Andre, I think you need to reread the OP's post, as neosonic stated...

>My problem is, after running my program several times (by using "start" command in vb6)... maybe around 100 times or so... I have got out of memory error.

Which means to me that neosonic is not releasing memory between each debugging session.

So NS, you are using the LoadPicture Function to load an image into the picture box, and then into an image list? Let me guess. You are using the image list with a ListView control to display thumbnails...

(Well if not, the following should apply anyways)

In form unload, clear the picture box by use the LoadPicture Function with no arguements...

Picture1.Picture = LoadPicture()

Then since the ListView is tied to the ImageList, you will need to "Clear" the contents of the ListView prior to clearing the contents of the ImageList...


But all of this means that you cannot use the "Stop" button in the IDE but instead allow you form to close naturally. Meaning the code needs to run to completion in form unload.

Good Luck


thanks, I will put them into my code and hopefully it can solve my out of memory error. I don't think that my program is big enough to use up all of the memory, if I free up all the unused memory everytime I finish. thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.