-
Aug 15th, 2018, 03:40 PM
#1
Thread Starter
Hyperactive Member
vb6 garbage collector
I have a program that queries and displays data to users that is supposed to run 24/7. The program is very simple, a timer control to know when to requery and a few basic controls.
Because it runs for days\weeks, the ram usage slowly increases until it gets an "error 7 out of memory" error or until the computer becomes so slow and unresponsive, you have to do a hard reset.
I've found that minimizing the window triggers something that resets the memory down to it's starting usage (12k). As a workaround, I programmatically minimize and restore the window to trigger the release and avoid the errors but this is causing another problem and I'd like to try something else.
Does anyone know why minimizing triggers the garbage collector? Is another way keep to free ram?
-
Aug 16th, 2018, 05:49 AM
#2
Re: vb6 garbage collector
There is no Garbage Collector in VB 6. That's a .Net thing.
In VB, you have to "clean up" after yourself.
If you create it, destroy it.
If you open it, close it.
Regards, Phill W.
-
Aug 16th, 2018, 07:04 AM
#3
Re: vb6 garbage collector
Eh?
mentioning "requery" implies some DB-stuff.
A classic would be something along the lines
Code:
'Public/Global Variable
Public MyRS As Recordset 'DAO or ADO or whatever
Private Sub Timer1_Timer()
Set MyRS = New Recordset
Set MyRS = DB.OpenRecordset(MyQuery)
End Sub
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Aug 16th, 2018, 10:22 AM
#4
Thread Starter
Hyperactive Member
Re: vb6 garbage collector
Originally Posted by Phill.W
There is no Garbage Collector in VB 6. That's a .Net thing.
In VB, you have to "clean up" after yourself.
So what happens to 's' in this below code? Does it stay forever because I didn't "clean up"?
Code:
private sub button1_click()
dim s as string
s = "do i live forever?"
end sub
for the record, my database connections and recordsets are set to nothing.
it still doesn't explain why the "clean up" doesn't happen until I minimize the window which strongly implies that the reference counting\garbage collecting\whatever can be held up by some combo of events
-
Aug 16th, 2018, 02:09 PM
#5
Re: vb6 garbage collector
Originally Posted by DllHell
So what happens to 's' in this below code? Does it stay forever because I didn't "clean up"?
The compiler will insert a call to SysFreeString for you but you probably know this already.
The point is that there is no GC at all as tear down is deterministic in VB6 i.e. there are explicit release/free statement inserted by the compiler all over the place.
cheers,
</wqw>
-
Aug 16th, 2018, 02:13 PM
#6
Re: vb6 garbage collector
Yes it really depends on how you have coded your app. Sounds like the problem is in the code somewhere. Public objects can be a problem if handled improperly as can form or class level objects.
The memory reducing when you minimize seems rather odd. Di you have code in your resize event that might explain this or perhaps using a 3rd party control of some sort that may be the culprit?
-
Aug 16th, 2018, 03:16 PM
#7
Thread Starter
Hyperactive Member
Re: vb6 garbage collector
Originally Posted by DataMiser
Yes it really depends on how you have coded your app. Sounds like the problem is in the code somewhere. Public objects can be a problem if handled improperly as can form or class level objects.
The memory reducing when you minimize seems rather odd. Di you have code in your resize event that might explain this or perhaps using a 3rd party control of some sort that may be the culprit?
There are no third party controls. I am using a listView from mscomtrl.ocx. Very few public vars and they are all simple types, not objects\classes\forms. Nothing in the resize code either. It is a tiny utility program and I am reusing database functions and procedures from other working programs.
-
Aug 16th, 2018, 05:33 PM
#8
Re: vb6 garbage collector
Originally Posted by DllHell
There are no third party controls. I am using a listView from mscomtrl.ocx. Very few public vars and they are all simple types, not objects\classes\forms. Nothing in the resize code either. It is a tiny utility program and I am reusing database functions and procedures from other working programs.
I don't know how possible for you is to perform tests, but I would test for example closing and re-opening the database.
You say "not objects", but in the database engine there are plenty of objects.
-
Aug 16th, 2018, 06:40 PM
#9
Re: vb6 garbage collector
I would start by looking at how the recordset is defined, opened and closed.
If it is increasing memory usage you should be able to see that in task manager and may be able to locate the source with a bit of testing.
-
Aug 16th, 2018, 10:53 PM
#10
Re: vb6 garbage collector
Originally Posted by DllHell
Because it runs for days\weeks, the ram usage slowly increases until it gets an "error 7 out of memory" error or until the computer becomes so slow and unresponsive, you have to do a hard reset.
Sounds like you have a memory leak. Perhaps this thread will help you identify the culprit.
Originally Posted by DllHell
Does anyone know why minimizing triggers the garbage collector?
I don't know if these links will clear up the confusion for you or just further muddle it:
Originally Posted by DllHell
Is another way keep to free ram?
Well, you could try SetProcessWorkingSetSize or EmptyWorkingSet or even /WS:AGGRESSIVE, but I don't think that will solve your memory leak problem.
Originally Posted by Phill.W
There is no Garbage Collector in VB 6. That's a .Net thing.
Originally Posted by wqweto
The point is that there is no GC at all as tear down is deterministic in VB6 ...
According to Wikipedia, COM's reference counting is actually considered as garbage collection.
-
Aug 17th, 2018, 03:10 AM
#11
Re: vb6 garbage collector
Originally Posted by Victor Bravo VI
I thought he was implying that VB6 does some sort of tracing GC. Hope that now OP agrees there is no separate garbage collector running on a separate thread that "spontaneously" frees memory and the source of this leak should be traced to dangling ref-counted instances and the resolution will certainly boil down to issuing a Set var = Nothing explicitly somewhere in his code.
This might not be so easy to pin-point as the problem could be in a 3-rd party code that he has no access to actually.
cheers,
</wqw>
-
Aug 17th, 2018, 05:01 AM
#12
Re: vb6 garbage collector
Originally Posted by DllHell
I have a program that queries and displays data to users that is supposed to run 24/7. The program is very simple, a timer control to know when to requery and a few basic controls.
Because it runs for days\weeks, the ram usage slowly increases until it gets an "error 7 out of memory" error or until the computer becomes so slow and unresponsive, you have to do a hard reset.
I've found that minimizing the window triggers something that resets the memory down to it's starting usage (12k). As a workaround, I programmatically minimize and restore the window to trigger the release and avoid the errors but this is causing another problem and I'd like to try something else.
Does anyone know why minimizing triggers the garbage collector? Is another way keep to free ram?
VB6 Developers don't Programm -Garbage- so we don't need a collector,
I'm gonna get -Wacked- for that one
EDIT:
jokes aside
is this an option, using a script with Task Scheduler
https://pythoncodesnippets.wordpress...ask-scheduler/
regards
Chris
Last edited by ChrisE; Aug 17th, 2018 at 06:11 AM.
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Aug 17th, 2018, 05:41 AM
#13
Re: vb6 garbage collector
Originally Posted by DllHell
There are no third party controls. I am using a listView from mscomtrl.ocx. Very few public vars and they are all simple types, not objects\classes\forms. Nothing in the resize code either. It is a tiny utility program and I am reusing database functions and procedures from other working programs.
Are you by chance continually adding items without removing any? That will cause out of memory errors eventually. The mscomctl version is particularly bad about this.
-
Aug 17th, 2018, 09:35 AM
#14
Thread Starter
Hyperactive Member
Re: vb6 garbage collector
Originally Posted by fafalone
Are you by chance continually adding items without removing any? That will cause out of memory errors eventually. The mscomctl version is particularly bad about this.
no, there is a fixed number of rows but the contents of the cells do change.
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
|