Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Garbage collection in VBA

I had read that its good practice to set instances of class to Nothing
to free up the memory.

Is there garbage collection in VBA?

Also is there any benefit to setting Application Object Model class
variables to Nothing upon exiting a procedure or function? For example

Dim myRange as Range

Set myRange = Something

Do some code

Set myRange = Nothing

Exit Function

Or is the memory allocated in the function returned to the heap when the
function goes out of scope?



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Garbage collection in VBA

Or is the memory allocated in the function returned to the heap when the
function goes out of scope?

For local variables, Yes.

--
Regards,
Tom Ogilvy

"Edward Ulle" wrote in message
...
I had read that its good practice to set instances of class to Nothing
to free up the memory.

Is there garbage collection in VBA?

Also is there any benefit to setting Application Object Model class
variables to Nothing upon exiting a procedure or function? For example

Dim myRange as Range

Set myRange = Something

Do some code

Set myRange = Nothing

Exit Function

Or is the memory allocated in the function returned to the heap when the
function goes out of scope?



*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Garbage collection in VBA

Read this NG post by Matthew Curland http://tinyurl.com/cq95p

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Edward Ulle" wrote in message
...
I had read that its good practice to set instances of class to Nothing
to free up the memory.

Is there garbage collection in VBA?

Also is there any benefit to setting Application Object Model class
variables to Nothing upon exiting a procedure or function? For example

Dim myRange as Range

Set myRange = Something

Do some code

Set myRange = Nothing

Exit Function

Or is the memory allocated in the function returned to the heap when the
function goes out of scope?



*** Sent via Developersdex http://www.developersdex.com ***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Garbage collection in VBA

To both of you thanks.

I've been wasting my time and fingers typing Set all class variables to
Nothing at the end of all my procedures.

Good article Bob.



*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Garbage collection in VBA

Edward,

Unfortunately, whilst Matthew is making a very good point (and he is a
respected MS developer), there are cases, automation comes to mind, where
not clearing down the objects is suspected of being the reason why Excel
sometimes fails to quit.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Edward Ulle" wrote in message
...
To both of you thanks.

I've been wasting my time and fingers typing Set all class variables to
Nothing at the end of all my procedures.

Good article Bob.



*** Sent via Developersdex http://www.developersdex.com ***





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Garbage collection in VBA

Bob,

I understand there are circumstance that explicit releasing of resource
is required.

In my case, I have a macro that is constantly running. It displays a
modeless dialog box with numerous options. I have only a few of my own
classes. Generally I'm using the Excel Object Model classes. Each
option of the dialog box fires up another module to do some processing
of data. Once that module is finished the procedure is exited and
control returns to the main dialog box module. Almost alway the class
instances are local to the module and can be release. So my concern was
does multiple calls to the modules cause accumulation of memory locks or
is it released. As Tom pointed out, if they are local I don't have to
explicit release.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I delete an infinite number of garbage cells to the right terry Excel Discussion (Misc queries) 2 April 4th 23 11:21 AM
Excel opening w/ garbage WLMPilot Excel Discussion (Misc queries) 2 December 13th 05 02:43 AM
MSCOMM returning garbage as input Marty[_5_] Excel Programming 0 August 29th 05 03:49 PM
Deleting garbage Sandra[_6_] Excel Programming 13 May 5th 05 05:47 PM
delete garbage from worksheet mkk Excel Programming 2 February 18th 04 07:31 PM


All times are GMT +1. The time now is 10:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"