By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,469 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,469 IT Pros & Developers. It's quick & easy.

What Should I Close?

P: n/a
In using DAO methods, I close recordsets and set them to nothing. When
a DAO.database is dimmed, I set it to nothing.

I have an application in which a user clicks on a control on a form and
a pop up form opens, using DAO to open recordsets close them, etc. The
user can go through many many controls clicking open this popup, so
recordsets are flying all over the place. After a while of this on a
computer with 2 Gigs of RAM on which I'm using to develop this app I got
a memory error and had to close out Access and start again.

I'm obviously leaking memory, can folks suggest where I look? should a
database object be closed?
--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Tim Marshall <TI****@antarctic.flowerpots> wrote in message news:<cl**********@coranto.ucs.mun.ca>...
In using DAO methods, I close recordsets and set them to nothing. When
a DAO.database is dimmed, I set it to nothing.

I have an application in which a user clicks on a control on a form and
a pop up form opens, using DAO to open recordsets close them, etc. The
user can go through many many controls clicking open this popup, so
recordsets are flying all over the place. After a while of this on a
computer with 2 Gigs of RAM on which I'm using to develop this app I got
a memory error and had to close out Access and start again.

I'm obviously leaking memory, can folks suggest where I look? should a
database object be closed?


General rule of thumb I've read here over the years is that you only
explicitly close what you open. That's the pattern in the help, so
I'm assuming that it's proper procedure...

From A2002 Help:
Sub OpenDatabaseX()

Dim wrkJet As Workspace
Dim dbsNorthwind As Database
Dim dbsPubs As Database
Dim dbsPubs2 As Database
Dim dbsLoop As Database
Dim prpLoop As Property

' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

' Open Database object from saved Microsoft Jet database
' for exclusive use.
MsgBox "Opening Northwind..."
Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
True)

' Open read-only Database object based on information in
' the connect string.
MsgBox "Opening pubs..."
Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
dbDriverNoPrompt, True, _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers ")

' Open read-only Database object by entering only the
' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening second copy of pubs..."
Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;")

<SNIP>
'Close all open databases

dbsNorthwind.Close
dbsPubs.Close
dbsPubs2.Close
wrkJet.Close

End Sub

I guess they don't set anything to nothing because in theory all
variables that go out of scope should get destroyed automatically.
May cause memory leaks - I have NO idea. (I know what I'm going out
as tomorrow night... the Scarecrow... head's just full of stuffin')
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.