Dereferencing objects: Am I living on borrowed time?

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,
I was just reading up on database corruption, on Allen Brown's pages,
and found a note suggesting to always dereference your objects by setting
them to nothing. I've seen this done, albeit inconsistently, by other
people. I don't think I've done it at all in my code. I've been living on
the assumption that Access did it for me when a subroutine or function
returned. Is this not true? I guess I want to understand the issue a
little better, before I spend a day adding a bunch of nothings to my code.

Thanks, Max
 
Max said:
I was just reading up on database corruption, on Allen Brown's pages,
and found a note suggesting to always dereference your objects by setting
them to nothing. I've seen this done, albeit inconsistently, by other
people. I don't think I've done it at all in my code. I've been living on
the assumption that Access did it for me when a subroutine or function
returned. Is this not true? I guess I want to understand the issue a
little better, before I spend a day adding a bunch of nothings to my code.


Dereferencing is a good programming practice regardless of
what the language is supposed to take care of automatically.
Access is known to have a couple of quirks where it doesn't
deal with the automatic dereferencing as it should, so just
follow the good practices guidlines and always do it
yourself.

In addition to setting object variables to Nothing as soon
as you're done using the object, don't forget to Close any
objects that you explicitly Open (OpenDatabase,
OpenRecordset, etc), but don't close objects that you do not
explicitly open (CurrentDb, RecordsetClone, etc).
 
Dereferencing is a good programming practice regardless of
what the language is supposed to take care of automatically.
Access is known to have a couple of quirks where it doesn't
deal with the automatic dereferencing as it should, so just
follow the good practices guidlines and always do it
yourself.

In addition to setting object variables to Nothing as soon
as you're done using the object, don't forget to Close any
objects that you explicitly Open (OpenDatabase,
OpenRecordset, etc), but don't close objects that you do not
explicitly open (CurrentDb, RecordsetClone, etc).


I'm all for good programming practices, especially since I'm teaching
myself a new language (with MVP help). Thanks for the good info.

- Max
 
Back
Top