Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error '7' Out Of Memory 1

Status
Not open for further replies.

MrVB50au

Programmer
Mar 16, 2003
326
0
0
AU
I've been working with my program for quite sometime now, and suddenly it's beginning to give me Out Of Memory errors where as it wasn't doing it before.

I don't understand why and yet I could have a fare idea what's causing it.

Could it be that I'm not closing forms after I used them properly? and what about after I opened an INI file? What's the best way to close an INI file and closing forms?

In my last question I asked about INI files and the DoEvent function, I had noticed that each time I go to open the same file that there are some settings that are being set than the first time I opened it.

Does all my problems seem to stem back to having too much loaded and not closing forms and files correctly?

Thanks again,

Andrew.
 
If you are using Instances of forms, remember to set the instance = Nothing when you are finished with it. If not the memory won't be released. This is especially true if your forms are using classes. But if you aren't using instances, make sure the forms are unloaded when you are finished.

Hope it Helps
Andy
 
What's the exact message?

If it's "Out of stack space", then you've got some uncontrolled recursion. This can happen if you have one event handler calling another one.

If it's "out of memory", then you're probably running on Windows 9x (95, 98, ME), and are running out of system resources. In this case, you'll have to be careful not to put too much on any one form, and make sure you minimize the number of forms open at any one time.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
chiph

It's Actually Runtime Error '7' Out Of Memory and I think you could be right as optimizing some of the code and unloading does seem to help. However, I have read somewhere where unloading a form doesn't always seem to free up memory and to do as your other suggestion will make sure all forms are out of memory by using the eg:
Set Form1 = nothing.

Thanks again,

Andrew.
 
MrVB50au -

Good practice is to try and free your allocated objects in the same method where they were allocated. You can't do it all the time, but you should attempt to.

An instructor I had in university called this "sandwich" code. You have two pieces of bread, with the meat of the method inbetween.

The trick is to remember to always write the "Set xxx = Nothing" right after writing the "Set xxx = New xxxType" line. You just have to develop the habit.

BTW, an excellent book that covers this sort of stuff is The Pragmatic Programmer It's mostly for O-O languages, but there are many things in there that are applicable to writing good VB6 applications.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top