- Local time
- Today, 05:45
- Joined
- Feb 19, 2013
- Messages
- 16,607
when an object is created, for good memory management it should be closed when finished with.
but how do you close a function which returns an object? Or doesn't it matter
for example a function could be structured like this
or like this
My question is - does the second method leave memory allocated, ultimately leading to a stack overflow? Any views on which is the better way?
but how do you close a function which returns an object? Or doesn't it matter
for example a function could be structured like this
Code:
function getRst(rst as dao.recordset, sqlstr as string)
dim db as dao.database
set db=currentdb
set rst=db.openrecordset(sqlstr)
set db=nothing
end function
'and called
dim rst as dao.recordset
getRst rst, sqlstr
'do something with rst
rst.close
set rst=nothing
Code:
function getRst(sqlstr as string) as dao.recordset
dim db as dao.database
set db=currentdb
set getRrst=db.openrecordset(sqlstr)
set db=nothing
end function
'and called
dim rst as dao.recordset
set rst=getRst(sqlstr)
'do something with rst
rst.close
set rst=nothing