G
Gordon Bentley-Mix on news.microsoft.com
Whilst debugging a template this morning, I discovered some interesting
behaviour regarding variables declared as Public. While variables with
'local' scope - i.e. those declared using a Dim statement, either at the
module or procedure level - are unloaded from memory once code execution is
complete, it appears that variables declared as Public are not unloaded until
all documents based on the template containing the Public variable are closed.
From reviewing my code, I see that I've encountered this problem previously
without really being aware of what was happening. However, in this latest
effort, the cause suddenly became clear. Previously, I resolved this issue by
'resetting' these variables explicitly: erasing Public arrays; setting Public
'number-type' variables to "0" (zero); setting Public Boolean variables to
"False", setting Public string variables to "" (null); etc. However, in this
new project I have approximately 30 Public variables, and resetting them all,
while not an especially onerous task, isn't necessarily something I want to
do.
Can anyone shed any light on why Public variables have such 'persistance'? I
would expect that once code execution is complete, any variables would be
unloaded from memory regardless of how they've been declared.
And if this is "standard" behaviour (i.e. something that I'll just have to
cope with in spite of my expectations ;-P), then does anyone know an easy way
to dump Public variables out of memory - or at least reset them - without
having to do so explicitly? My big concern is that I have several similar
templates that use identically-named Public variables. I'm a bit worried that
if a user has 2 or more docs based on different (but similar) templates open
at once, there might be a conflict if these identically-named Public
variables are still hanging around in memory if the user switches between
docs.
--
Cheers!
Gordon Bentley-Mix
Word MVP
Please post all follow-ups to the newsgroup.
Read the original version of this post in the Office Discussion Groups - no
membership required!
behaviour regarding variables declared as Public. While variables with
'local' scope - i.e. those declared using a Dim statement, either at the
module or procedure level - are unloaded from memory once code execution is
complete, it appears that variables declared as Public are not unloaded until
all documents based on the template containing the Public variable are closed.
From reviewing my code, I see that I've encountered this problem previously
without really being aware of what was happening. However, in this latest
effort, the cause suddenly became clear. Previously, I resolved this issue by
'resetting' these variables explicitly: erasing Public arrays; setting Public
'number-type' variables to "0" (zero); setting Public Boolean variables to
"False", setting Public string variables to "" (null); etc. However, in this
new project I have approximately 30 Public variables, and resetting them all,
while not an especially onerous task, isn't necessarily something I want to
do.
Can anyone shed any light on why Public variables have such 'persistance'? I
would expect that once code execution is complete, any variables would be
unloaded from memory regardless of how they've been declared.
And if this is "standard" behaviour (i.e. something that I'll just have to
cope with in spite of my expectations ;-P), then does anyone know an easy way
to dump Public variables out of memory - or at least reset them - without
having to do so explicitly? My big concern is that I have several similar
templates that use identically-named Public variables. I'm a bit worried that
if a user has 2 or more docs based on different (but similar) templates open
at once, there might be a conflict if these identically-named Public
variables are still hanging around in memory if the user switches between
docs.
--
Cheers!
Gordon Bentley-Mix
Word MVP
Please post all follow-ups to the newsgroup.
Read the original version of this post in the Office Discussion Groups - no
membership required!