I have this little problem (at least I hope it is little).

My vb6 program behaves differently when I execute it with the execute button in vb6 and when I execute it by using the compiled .exe file.

I have a huge 2 picture boxes which loads 2 x 5 mb .png picture file.
I always use picturebox.picture = loadpicture() and clear the imagelist that I am using, everytime I unload the form.

It works fine when I execute it with the execute button in vb6, I can open and close it over and over again.
But when I execute it by using the compiled .exe file, I can open and close the program for 2-3 times, but it gives me the "out of memory" error when I finish. I dunno why it does it?

How can I clear the "used" memory when I exit the program/ form? so I can avoid this to happen? Maybe the memory from my video memory has not cleared properly :(

Also another thing.. I would like to compact the filesize of my .png file when I save it, how can I do it with the savepicture method? or with any other method? The picture size is a huge A3 size, but 5 mb is a killer for any video memory.

thanks.

How are you instantiating the form? Are you starting up from sub main() or from the form itself?

How are you instantiating the form? Are you starting up from sub main() or from the form itself?

thanks for your reply.
I am starting my program with sub main(), but I do not know what the problem it might cause. thanks

It isn't causing a problem per se. However, depending on the the technique you use to instantiate your form and the order you unload things it might be leaving "memory leftovers".

I did some science experiments with my own picture (it was a jpeg not a png) and didn't have any problems. I instantiated the form from without variables, loaded a single picture box in the form_load event, unloaded the picture in the form_unload event and had no problems at all. Memory returned to where it was before execution (even after repeated executions as .exe, even multiple concurrent executions as .exe).

Maybe you can post some of your code, because it looks like there's something else going on that might not be related to your picture at all.

that is a relief :) thanks a lot. Ok the other thing that I can think of the database connection.

---------------------------

DBEngine.SystemDB = locationMainDB & "\system.mdw"
DBEngine.DefaultUser = "User" '"admin"
DBEngine.DefaultPassword = "Password"
Set WrkJet1 = DBEngine.Workspaces(0) 'CreateWorkspace("", "Admin", "Password", dbUseJet)
Set DB = WrkJet1.OpenDatabase(locationMainDB & "Data.mdb")

-----------------------------------------------------

I initiated this in my main sub, when I initiated the main form and it left open until the end and it never close, because I do not know how to close it.

Note: but I close every recordset that I open, such as

---------------------------------------------
Set E = DB.OpenRecordset("SELECT DISTINCTROW Table1.* FROM Table1;")
'will be always closed
E.close
---------------------------------------------

Will it may be a problem?

I will post more of my code, if I can think of something else.
thanks a lot.

When you're ready to close the database, just use:

DB.Close
Set DB = Nothing

The close is self-explanatory. Setting your object variable to "Nothing" frees pointers and memory. Everywhere you are using "Set variableName = myObject" then you should be sure to do a "cleanup" and set the object variable equal "Nothing". Places like DB, WrkJet1, E, and so on.

You can look in the VB help file for a further explanation or the Nothing reserved word. That may clear up your problem.

thanks, I will definitely go through my code. thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.