Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Releasing Memory 2

Status
Not open for further replies.

spats

Structural
Aug 2, 2002
655
I'm using quite a bit of VBA code in a excel spreadsheet, and everytime the code executes, memeory usage goes up by about 100K, according to Task Manager. This memory is never released, and available memory just becomes less and less with each execution. Is there some procedure I can write at the end of my code to release the memory?
 
Replies continue below

Recommended for you

That will depend on what you're doing, and where in the VBA code you're doing it. Most likely, you're allocating memory for dynamic objects but not release those objects when you're done. Have you narrowed things down to one or more specific sections of code, and if so, what are you doing in those sections?


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The code is full of altering and filling in cell ranges. Sometimes individual cells, sometimes cell groups. I know that a range of cells is considered an object in vb’s eyes, but i have not named each object individually. I am hoping there is a general way to release ram when procedure is complete.
 
When writing VB code, it's a good idea to release all of your objects by setting them to nothing. It's less important with variables decalared as strings, or other types, but application objects should be set to nothing. i.e.:

dim objRange as Excel.Range

blah blah magic code blah.

' we're done with the range, so clean up.
set objRange = Nothing\



Tim Grote - The Irrigation Engineers.
 
Check if you have globally declared arrays or objects. They will not dissappear when code execution is over. Clean up at the end of routine:
Erase MyArray()
Set MyObject = Nothing

But it could be some of Excel problems as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor