|
-
Dec 21st, 2023, 04:34 PM
#1
Thread Starter
Fanatic Member
Out of Memory error
My project is really complex and absolutely huge. 335,000 lines of code. 8570 procedures. 18320 controls. 450 files and forms. So eventually I was bound to run into an out of memory issue.
But recently as a user exits the program or exits one form to go back to the main form they are getting an Out of Memory error. Hey... I'd get it if they were opening a new form or even opening the program. But closing a form or closing the program?
Any suggestions?
-
Dec 21st, 2023, 04:43 PM
#2
Re: Out of Memory error
Look for a recursion bug?
-
Dec 21st, 2023, 05:01 PM
#3
Re: Out of Memory error
Yeah it's probably the fault of some code in the "Form_Unload" or "Form_QueryUnload" events that is causing other closed forms to be reloaded again going into a vicious circle.
-
Dec 21st, 2023, 07:20 PM
#4
Addicted Member
Re: Out of Memory error
Not sure if this is a solution, but make the .EXE LargeAddressAware
Code:
[VBCompiler]
LinkSwitches=/LARGEADDRESSAWARE
Add the above to your .VBP file.
An alternate method would be to modify the .EXE using Editbin.exe
Joe
-
Dec 22nd, 2023, 03:00 AM
#5
Re: Out of Memory error
why create such a huge project all-in-one?
not sure what kind of program you are doing, but can't u create separate projects?
I mean, if u call "forms" u could even shell executables, if u need communication between them theres many ways of doing that.
-
Dec 22nd, 2023, 05:02 AM
#6
Re: Out of Memory error
My 2 main projects have more than 500k off lines, 262 forms, 8274 sub/functions...
No out of memory.
Check if you use GDI, release all objects etc...
it takes time of course
-
Dec 22nd, 2023, 10:52 AM
#7
Re: Out of Memory error
Yeah, my primary project is near that size, and I've never had anything close to a memory problem. It's amazing how tightly VB6 code compiles, even for hundreds of thousands of lines of code.
Personally, I think Dilettante nailed it, you've got some kind of recursion problem that's overflowing your stack. This could be a simple recursion problem, such as some procedure making calls that eventually re-call that procedure. Or, it could be something more complex, such as some code in a class (or form, or UC) that's somehow getting into a loop where it's making unlimited instantiations of itself.
Either of those will produce your symptoms.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Dec 22nd, 2023, 06:59 PM
#8
Re: Out of Memory error
Just thinking about this one a bit more (and reading other replies), personally, I'd never use the LARGEADDRESSAWARE linker option (and I don't use it on my very large project). The primary reason for this is two-fold: 1) I'd have to make absolutely sure that all my pointer math took that into account, and 2) There's no way of knowing if every single library I call (even when not using API calls) has considered that. As Dilettante has stated before, it's like planting a time-bomb in your code. I understand that Wqweto has used it for years with no problem, but I really don't think "too much code" is your problem.
And my second thought has to do with another reason you may be getting a memory overflow ... a huge array, possibly a huge String array. Or even just several unreasonably large strings. It wouldn't take much more than about three ridiculously large strings to overflow memory.
And lastly, as mentioned above, some badly written code with API calls may have memory leaks in it. It's difficult to have a memory leak without API calls though, but it's easy when you're using them (if not used properly). However, I doubt a memory leak is your problem, unless this is some program that runs for weeks or months at a time without restarting and/or you're doing something with API calls over and over 100s (or 1000s) of times, causing enough memory to leak to make a difference.
Anyway, I thought I'd post my thoughts. Good luck finding your problem.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Dec 23rd, 2023, 10:25 AM
#9
Fanatic Member
Re: Out of Memory error
Do you have any error handling to help pinpoint where the exception is getting thrown?
For what it's worth I have seen vb6 throw random out of memory errors when some other process has chowed thousands or on 64 bit windows 10s of thousands of HANDLES.
Some av code leaks handles. Serarchindexer.exe on some versions of windows leaks handles.
Maybe look for something else on the impacted boxes that might be behaving badly and impacting your code.
-
Dec 23rd, 2023, 11:05 AM
#10
Fanatic Member
Re: Out of Memory error
My first spontaious question is when it seems you use several controls for the amount of functions - every control use a pointer and call to to the registry so I wonder if you can reduce the amount of controls and "re-use" some of the controls so you save the memory pointers to the registry. And even "re-use" the some procedures for similar tasks and put in "if"-options in the procedures. Just a common sence question. Let's say for example that 3 controls can do the same/similar job?
-
Dec 23rd, 2023, 11:43 AM
#11
Re: Out of Memory error
Could be one of VB6 runtime bugs like this one:
Dim a() As Byte, s As String
a = vbNullString
s = StrConv(a, vbUnicode) ‘—- OOM here
You need good error handling and other infrastructure to grow your project above 300k LOC. Otherwise it will collapse under its own weight when you hit runtime and compiler bugs. Recently we got OOM during compilation (on our build server only) after innocuous code change. The project was working (and compiling binary) perfectly fine on dev machines.
-
Dec 23rd, 2023, 01:18 PM
#12
Fanatic Member
Re: Out of Memory error
Why Dim a() As Byte when Win64 needs bigger varables. At least integers. And replace all strings with LONG_PTR.
-
Dec 23rd, 2023, 01:26 PM
#13
Fanatic Member
Re: Out of Memory error
Dim a() As Integer, lpS As LONG_PTR, s As String
a = 0
And if you need a string after all...
s = StrConv(SysAllocString(lpS),vbUniCode) <-- This will not be OOM
With other words REPLACE ALL Strings with either Integer or LONG_PTR values...all in string buffers to Integers and ALL out Strings to LONG_PTR.
Last edited by nebeln; Dec 23rd, 2023 at 01:32 PM.
-
Dec 23rd, 2023, 03:15 PM
#14
Re: Out of Memory error
An Out of memory error is a general error that can be caused by multiple things, in general after reaching some limit.
For example when GDI objects count > 10000. Or large arrays that cannot be redimed contiguous. Or other reasons.
-
Dec 23rd, 2023, 05:30 PM
#15
Fanatic Member
Re: Out of Memory error
As I tried to explain if you got hundredreds or thousands of calls that are for STRINGS it WILL be OOM and therefore I suggested to exhange them to Integers if inbound arrays etc and LONG_PTR for outbound pointers.
-
Dec 23rd, 2023, 08:24 PM
#16
Re: Out of Memory error
In a case like this, you cannot guess.
You need to "chase" exactly where the error occurs, what exact line. And check what resource is running out (or bug, whatever).
There are too many things that can cause this error.
To have a huge project with many LOC, controls and forms... has probably little to do with the issue.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|