Link to home
Start Free TrialLog in
Avatar of rbend
rbendFlag for United States of America

asked on

Question about DIM statements

If I have a DIM statement inside a timer or a frequently used subroutine, does that re-DIM the variable each time? And does that make my app use up resources that it shouldn't? That's my problem. My app runs a while and the machines run out of resources.
What other things can I adjust or fix to help minimize this problem.?
Avatar of Erick37
Erick37
Flag of United States of America image

You can Dim within any function, it does not take up more memory every time the function is entered.

There are lots of things which may be causing a memory leak.  What are you doing in the timer?  Are there any other repetitive tasks which may be causing the problem?
ASKER CERTIFIED SOLUTION
Avatar of Jon_Raymond
Jon_Raymond

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not trying to answer this question, because both Erick37 & Jon Raymond have already done so, but I thought rbend could use a bit more of an explanation.

A procedure-level variable declared with the DIM statement retains its value until the procedure is finished running. If the procedure calls other procedures, the variable retains its value while those procedures are running as well.

If a procedure-level variable is declared with the STATIC keyword, the variable retains its value as long as code is running in any module. When all code has finished running, the variable loses scope and its value. Its lifetime is the same as a module-level variable.

A module-level variable differs from a static variable. In a standard module or a class module, it retains its value until you stop running your code. In a class module, it retains its value as long as an instance of the class exists. Module-level variables consume memory until you reset their values.

Variables dimensioned as object pointers are supposed to release memory in the same way, however, that is not always the case. Memory leakage can occur, so as Jon recommends, set the object variable to NOTHING as you exit your procedure.
By the way, If your timer event procedure takes longer than the timer period, you'll be nesting event calls. That'll earn you a stack overflow. Try commenting out your timer procedure & see if that fixes the resource problem. If it does, you know what to do.
Avatar of rbend

ASKER

thanks all of your for your time !
Happy Holidays