Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:02:35+00:00 2026-06-07T06:02:35+00:00

Lately I’ve bumped into a question that made me pounder; it kept me busy

  • 0

Lately I’ve bumped into a question that made me pounder; it kept me busy and I couldn’t find a transparent explanation for it on the net.
It is related to the destruction of Excel objects (which I use all the time and never really questioned before).

Background leading to my question:
With regular objects, you can instantiate an object using the keywords SET and NEW.
For example:

Set classInstance = New className

Whenever we instantiate this way, the object is created in the heap memory and the reference counter is increased by 1.
In case I don’t add more references, the following statement would bring the reference count back to zero:

Set classInstance = Nothing 

When the reference count goes to 0, the object is destroyed and cleared from memory and the “classInstance” points to .

What I’ve read:
When we use the “CREATEOBJECT” function, it returns a reference to a COM object.

Set oApp = CreateObject("Excel.Application")

Even though we could say:

Set oApp = nothing 

The objects’ reference count will go to 0, and oApp will not point to the object anymore.

My questions:
1) Why is it that this type of object requires to call the method .Quit before the object is actually being removed from memory?
The same goes when adding a reference to a workbook object (workbooks.add or workbook.open) which requires the .close method.
Why can’t these objects be automatically destroyed when bringing the reference count to zero?
Which is the case when we say for example:

set oRange = nothing 

2) And is there a need to say:

oApp.Quit
set oApp = nothing 

Since the Application object is already cleared from memory when applying .Quit, there is no object to be released anymore.
The only reason I could come up with, why oApp would be set to Nothing after Quit, would be because it could be pointing to an unused memory location (on the heap) and could lead to confusion later if this memory would be re-assigned (although in VBA I find this hard to imagine).
I was questioning myself if this conclusion is correct and I would like to receive confirmation for that from someone who knows the answer.
Please, tell me if I see this wrongly.

3) What they call in VBA “a reference to an object” (such as oApp in the code above), I see them as pointer variables in C.
Would it be safe to use this statement or again, am I seeing this wrongly?

Generally is not hard to apply .Quit and set to nothing, but it would be nice to receive some accurate information on the topic. So that I know for 100% percent why I am doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:02:37+00:00Added an answer on June 7, 2026 at 6:02 am

    Good Question 🙂

    Excel controls the creation of its objects. Likewise it also controls their destruction.

    Setting oApp = Nothing just destroys the object reference. It doesn’t remove the Application. To destroy an Excel object, you have to use it’s .Quit method.

    Whenever you do, Set x = Nothing, the reference(pointer) named x to its relevant object is removed. This doesn’t mean that the object itself will be removed from the memory.
    Whether the object will be removed from memory or not, depends on various factors.

    1. Whether there are more references pointing towards the same object. If there are, the object will not be removed. The reference count must be zero.
    2. The internal implementation of the destructor of that object.

    The .Quit method is defined to graciously remove all the memory objects excel has allocated, and close itself.

    It is similar to calling Close on a form in VB6. Take for example, a form in vb6.

    Dim f As Form
    Set f = Form1
    f.Show
    
    '
    '~~> Rest of the code
    '
    
    Set f = Nothing
    

    Will this destroy the form? 🙂

    FOLLOWUP

    How about question 2? Thanks – Kim Gysen 14 mins ago

    enter image description here

    It might not be exactly as shown here, and compiler optimizations may make things behave differently… but this is the basic concept that is at work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lately I bumped repeatedly into the concept of LFSR, that I find quite interesting
Lately I'm interested in the topic of genetic algorithms, but I couldn't find any
Lately, I'v been struggling with an annoying situation on ASP.NET MVC. Here's the story
Lately I had an issue with an array that contained some hundred thousands of
Lately, I've gotten some weird linker errors. I've been taught that there's two ways
Lately I've been running into some subtle layout issues in my iOS app. For
Lately I've been wondering if there's a difference between initializing the variables that have
Lately, I've been wondering how to find the difference between two files with PHP.
Lately I've had a question, what I'm trying to do is read data from
Lately, we've been seeing exceptions like this in our .NET (.asmx) webservices: System.Web.Services.Protocols.SoapException: Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.