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!

Memory hogging

Status
Not open for further replies.

Trowser

IS-IT--Management
Dec 16, 2002
125
0
0
GB
I seem to have a problem with my program not releasing memory.

I am monitoring the momory use of the program.
It accesses MS Access DB's and there are many forms which can all be open at the same time and quite a few DB's that can aswell.

No when the user unloads a form using the little X in the top right or by clicking on the cmdexit button I have the following code

Unload me
DBconnection.close

I have this on all the forms.
Now I thought when u told it to unload it released from memory but it isn't and when u used the close command on a connection to a DB also unloads the DB from memory.

Could anyone give me any pointers on how to make sure everything clears out from memory
 
To release the memory a form is holding you have to set it to nothing.

Set Form1 = Nothing

Usually this code is placed in the QueryUnload or the Terminate event. Thanks and Good Luck!

zemp
 
Just a minor point.

Set Form1 = Nothing

merely decrements the form's reference count by one. If, and only if, the reference count is reduced to zero will the object be released.
 
strongm, can you elaborate. How is the reference count increased and how can you determine what it is?

I got this tip/code from this forum myself and now you are saying that the tip was incomplete... Thanks and Good Luck!

zemp
 
also then I have DB connections seen below

dim Conn as new adodb.connection
dim Rec1 as new adodb.recordset
dim Rec2 as new adodb.recordset
dim Rec3 as new adodb.recordset
dim Rec4 as new adodb.recordset

how do I get all of that to unload from memory as

conn.close doesn't seem to do that
 
I use 'set rs = nothing'. Similar thing for command and connection objects.

They are also suppose to be destroyed when they lose scope. Thanks and Good Luck!

zemp
 
I use 'set rs = nothing'. Similar thing for command and connection objects.

They are also suppose to be destroyed when they lose scope.

Another line of code I use is on large dynamic arrays after they are not needed anymore.

Erase myArray

That is suppose to reduce the array to what it was before you first redimed it. Thanks and Good Luck!

zemp
 
still seeing no change in memory use after the program closes after implementing these ideas.

set form1 = nothing
set record = nothing
set connection = nothing
 
do you pass your recordset to another form to do some other processing?
if yes, then you should also release those as well, if not, like strongm said, setting it to nothing only decrements the reference count and not deallocating the object itself.

in the below example, the recordset object will only be destroyed after Form2 is unloaded:

Code in Form1:

Dim rstData as New ADODB.Recordset

Private Sub Command1_Click()
Set Form2.rstPass = rstData
Form2.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set rstData = Nothing
End Sub

Code in Form2
Public rstPass as ADODB.Recordset

**************
zemp: strongm, can you elaborate. How is the reference count increased and how can you determine what it is

reference count is increased whenever you add a reference to an object. in the below example, reference count for object B will be two:

Dim A as ADODB.Recordset
Dim B as New ADODB.Recordset

Set A = B

unfortunately, we cannot track the reference count.

 
Try changing these declations:-
dim Conn as new adodb.connection
dim Rec1 as new adodb.recordset
dim Rec2 as new adodb.recordset
dim Rec3 as new adodb.recordset
dim Rec4 as new adodb.recordset

to this format:-
dim Conn as adodb.connection
...
set conn= new adodb.connection

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top