Memory Issues

jon_sg

Registered User.
Local time
Tomorrow, 07:04
Joined
Oct 5, 2003
Messages
41
Can someone help me out in fully understanding the life time of Variables and Objects in VBA.

I am currently developing a project for a client, as some of the machines the application side will be deployed on are pretty old, I need to watch the memory useage.

Where possible I have stored procedures as seperate public modules and pass values from event procedures through Args call [Name]([Arg1], [Arg2]) etc.
All the variables in the Public Modules are declared Private in the sub / function not the declarations part.
I have managed to avoid the use of statics and Public Module level variables.

When a form or report is closed is the module removed from memory, likewise after a called module has finished running? If not is there a way that to Explicitly destroy all variables and objects, releasing memory, after the procedure has finished running?
Any general tips on minimising memory usage would also be very handy

Thanks in advance

Jon
 
Jon,

An object is destroyed and memory reclaimed when the last object variable pointing to it goes out of scope or it is explicitly set to nothing.

Code:
Dim TextBox1 as New TextBox 
Dim TextBox2 as TextBox

Set TextBox2 = TextBox1
'Two variables are pointing to the same object.

Set TextBox1 = Nothing
'Memory still in use here because textbox2 is 
'still pointing to the object.

Set TextBox2 = Nothing
'Object is now destroyed.

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom