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!

I have a memory leak. Please Help 1

Status
Not open for further replies.

jmgrin

MIS
Jan 4, 2002
32
0
0
US
I am experiencing what appears to be a memory leak in several of my VB 6.0 applications. To try to identify the problem, I've created a new application, inserted the Beginning form from one of the applications I'm having a problem with. The form has 5 command buttons. Here is the code from the form:



Global dbclass As New ADODB.Connection<--This is defined in a
module called main. It is the only
thing in the module


Private Sub Form_Load()
MakeConnection
End Sub

Private Sub Form_Unload(Cancel As Integer)
CloseConnection
End Sub
Private Sub cmdAction_Click(Index As Integer)
Dim MenuOption As String
frmDERMenu.Hide
Select Case Index
Case 0
MenuOption = &quot;STDT&quot;
Case 1
MenuOption = &quot;JOBC&quot;
Case 2
MenuOption = &quot;FREQ&quot;
Case 3 'Exit
Case 4 'Create QUALS file
MenuOption = &quot;QUAL&quot;

End Select

Unload frmDERMenu
End Sub

Sub MakeConnection()

Set dbclass = New ADODB.Connection

'Create the connection.
dbclass.ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; _
& &quot;Data Source = &quot; & App.Path & &quot;\DER.mdb&quot;
dbclass.Open
End Sub
Sub CloseConnection()
dbclass.Close
Set dbclass = Nothing
End Sub


I have the program compiled to a .exe file.
What is happening is I execute the program and display the form and then immediately exit. Then if I wait 1/2 hour to an Hour, and try again to execute the program I get the error:

(myprogram0.exe - Application Error. The instruction at 0x77fab813 referenced memory at 0x00000058. The memory could not be read.


Does anyone see any problem with this code or know of an existing problem with the data access driver?

Thanks for any help you can give me.
 
I'm not a great expert on this, but can't read the memory doesn't appear to be a memory leak, rather some problem with the memory or the code block that's reading it. Memory leaks should give an out of memory error, but long before that, should be using the disk as virtual memory. As such, the program would slow way down and take everything else with it before actually returning an error.

Don't automatically rule out a bad memory chip. If this runs the same way on more than one machine, chances are you don't have one.

Then, I would remove the as new from your global connection, just because it's very inefficient. Not that that will fix your problem. Oh, wait a minute! It just might, since you set = new connection later on. That might make for some weird behavior. See if that helps.

If frmdER is the form that has the code, use &quot;Me&quot; instead of the form name.

Sometimes creating disconnected recordsets will help isolate a problem.

Bob
 
Thanks for your response. I tried removing the &quot;new' from the global declaration and changing the form name to &quot;me&quot;. Neither made a difference. I am sure the cause is not bad memory because it is happening on more than one machine.
The problem started occurring when the Windows 2000 hotfix QB15021 which affected the Windows kernal was installed. The fix addressed security issues so I'd rather not uninstall it. (The problem does not occur on a machine that does not have that hotfix applied.)

You suggested creating disconnected recordsets to isolate the problem. Could you explain what you mean by that?
 
did you mean QB15021 or 815021

there may be some info here that may be of use to you:-


maybe the bit about the buffer overrun?!?!?

with regard to declaring objects as new see cajuncenturians post in thread222-471548

ps sorry about stretching the thread [lol]

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @
 
Try

Private Sub Form_Unload(Cancel As Integer)
CloseConnection
' Clear hidden implicit object variable that
' has the same name as the form. Replace
' thisformsname with actual form name name.
set thisformsname = Nothing
End Sub

Private Sub Form_Terminate()
' DO NOT refer to From in this routine.
Debug.print &quot; I actually ended&quot;
End Sub
Make sure that there are no other references to the form.

If you do not see and Debug output then the form class never terminated. UNLOAD only releases resources used by the form. It does not terminate the instance of the form. The form terminates when there are no more references to the form.

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Again, thanks for the responses.

I set the form to nothing and made sure that it was terminating properly. It has not fixed the problem.
Any other thoughts?

Adoozer,
You were correct, I meant 825012. The knowlegebase article wasn't much help. It talks about the terrible things that could befall your system if you don't apply the patch but doesn't give any indication on how you could inadvertently cause a buffer overrun. The code listed in my first post is really all there is to my test project. I was hoping there was something I was blatantly overlooking. I'm at a loss.
 
is that all the code in the project??

i only ask because ive been trying to make it throw errors but i cant!!

secondly... why are u using global?!?!?

im pretty new to vb at a high level (been coding in it for about 2 years) but i cant see why you would want to make an object global

looking forward to helping you solve it!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @
 
Public instead of Global is preferred, the latter preserved for backward compatibility.

Ok. What service pack are you using with VB?

Bob
 
Thanks for the tip on global. I didn't know what the difference was.

I am using VB Service Pack 5.

Yes, that is ALL the code there is in the project.
The error doesn't occur right away. Once I load the form and exit from it, I need to wait at least an hour before trying to load it again to bame the error happen. If I try any soon I don't get the error.

I have tried removing the db connection code. When I do, I don't get an error.

 
I take that back. Removing the code for the db connection does still cause the error.
 
Hi,

Once You declared the conection New You don't have to Set it in Your MakeConection sub.

After You close the application check if the DER.ldb disapers!?

What is the version of ADO. I 've experienced somthing like this with ADO 2.6 and ADO 2.7.

Use ADO 2.5.

Tibi
 
These errors are usually a problem with the system running the code rather than the code itself. If you built this system yourself, I would back off your memory timings. If it is just an OEM machine, you may have some bad ram.
 
The problem is occurring on two machines so I don't think it would be bad ram. The error starting happening after these machines were reconfigured (i.e. hard drives reformatted and the operating system and software reloaded.)

Another piece of information that may ring a bell with someone is when the error message appears I can click ok to quit or cancel to debug. When I hit cancel, it goes into Visual C++ and a second error message:
&quot;Unhandled exception in myapp.exe(NTDLL.DLL) access violation&quot;

I checked the Windows 2000 patches that were applied to these machines and one Q815021, has an update to NTDLL.DLL so I'm making the assumption this may have something to do with it.

 
Yea it can also be caused by software.

If these two machines were loaded with the exact same image, then it could very well be a .dll or something like that. I doubt it is your code though.
 
You might be on the right track there, JM. I tried googling around (did a search on this error string) and there were pages and pages of problems on this, 3rd party apps like Quickbooks, the whole nine yards. The general feeling that I got was that Microsoft had a problem with this error, and was sending out patches and fixes and whatnot. I guess the answer is to apply the patch or whatever that makes the system work.

I've heard that Linux is a pretty good opsys....(resistance is futile....you will be assimilated....)

:)

Bob
 
Thanks to everyone for your help. My problem isn't resolved, but I've gotten some good tips on making my code more efficient.
 
After loading the program and exiting, have you checked Task Manager to see if the program is really being unloaded from memory?
 
Yes I have. It seems to unload just fine.
 
Hi,

When you re-run the application at what stage does it go tits up at? Do you see your menu, just after you make a selection etc.

See if there are any pathces for Access as well and rebuild your DB just in case.

Also, it may not even be your application that causing the problem. What else are you running on these machines?



William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top