Freeing Resources

I have a program that is running infinitely, it sleeps for 15secs and then restart again (using sleep function), the problem is after hours of running, the memory that it uses increases. i.e. when it starts it uses 4K of memory for after about 8 hours the memory used is like 150MB. what can i do, the program basically opens databases in SQL and does some computations to it.
Who is Participating?
manoj_rConnect With a Mentor Commented:
You can free up the objects you use by using the Nothing statement.

Set Form = Nothing
Set recordsets = Nothing
Set database = Nothing

and so on

This will explicitly free up the resources used by the objects.
I wasn't Aware that VB had a sleep function, but . . . .

It sounds like you could have a few problems, i'd need more info to be sure, but check for these:

1.  Memory Leak:  If your program is loading and unloading itself, be sure to use the UNLOAD (form) function.  Also could occur when you open/close the database.

2.  Program Storage:  If you are using arrays and don't need the data for other computations, be sure your clearing out the old data, or data you don't need.

that's about it for me.  Basically, look for any place in which the program is not shutting down correctly, OR that you are emptying out your program storage.

                                   -- Zabman :-)
nasiaAuthor Commented:
isn't set object = nothing same as object.close.... if not does this mean i have to put a set object = nothing to all recordsets after i close it, even if its not a global variable???
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

You will be better off doing that, yes. To summarise

1 If any of your object variables (recordsets, for example) have a "close" or similar method, execute it.
2 Unload all forms and any controls loaded in code
3 Set all object variables to Nothing

nasiaAuthor Commented:
its hard work... i've set all my recordset/database variable to nothing... i dont use any forms so theres no problem there... i'll observe my prog bahavior...
Make sure you are also setting the database connection to nothing unless you are absolutely certain you are not opening a database connection (login) every time you go to the database.  DB connections, more so than the recordsets can chew up memory because they drag in alot of overhead with them.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.