AC320.2 TS 4:32 - I noticed that you create the object db and rs and then you destroy it (Clean it up) backward - i.e. set rs to nothing then the same with db. I assume by this that there is a particular order of creation and tidying. It this assumption correct?
Reply from Richard Rost:
This just goes back to my C/C++ programming days.
In C/C++ you have to remember to manually clean up any variable pointers and other objects yourself, and in the correct order, otherwise you end up with craziness in your programs. Things called NULL POINTERS (pointers to nothing) can wreck havoc in your programs.
Think of object variables like plastic containers. If you declare a variable to a database object, that's a big container. If you then declare a variable to a recordset, then that's a container INSIDE a bigger container. It's dependent on the database object to exist.
Well, if you destroy the database pointer first, then the recordset pointer really doesn't reference anything useful since it's parent is gone. It's a small container floating out in space with nothing holding on to it. :)
HOWEVER, none of this really matters in VB or VBA because Visual Basic is very good at cleaning up after you. The guys who created VB realized that most people using it aren't professional programmers, so they made it so the language cleans up most things like this for you... unlike in C/C++ where you have to do all of the housekeeping yourself... it's a trade-off for more power to control variables right down to their memory address.
Anyhow... to answer your question, it's good FORM to clean up dependent variables before their parents, but it's not 100% necessary in VB. In fact, by default, whenever you exit a sub or function, VB will clean up that memory for you... but don't get used to it. Try to remember to clean up your variables on your own. It's a good habit to be in if you do ever decide to move on to "grown up" programming languages. :)
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Microsoft Access 320.