OpenArgs (my) class way (3 Viewers)

JFTR: VBA does not have garbage collection. Memory for object variables is released based on COM reference counting.
 
I thought so. But I usually iterate and destroy all the items before destroying the container object. After all, if we really trusted the garbage collector, we wouldn't even consider destroying the container object...
No you do not. You do not destroy anything. All you are doing is releasing a pointer. But if this makes you feel better continuing doing it.

If you believe that VBA does not have a trusted clean up, I say prove it.
All this discussion about setting objects to Nothing is usually a complete waste of time. What you think you are doing is not really doing anything. You are simply releasing a pointer. You are not triggering "garbage collection" or memory clean up. VBA takes care of that.

There are times to close open connections and there are a few times to set objects to nothing. But you are really better off understanding the exceptions instead of thinking you are doing something by setting everything to nothing. At the most I set objects to nothing 1% of the time, but it is for a specific reason. Some of this is described here.



People find it easier to just set all objects to nothing based on an urban myth, than trying to understand when and why.

You can disagree with this, and again I say prove it. Show some cases where the code fails when not setting something to nothing. I can demonstrate some of those cases.

I the last twenty years of actively posting stuff on forums, I am sure I have posted 100 of thousands of lines of vba code, 1000s of example dbs, 100s of class modules and rarely if ever set an object to nothing. Only once did someone come back and say the code failed. And this case falls into one of those exact cases explained in the article that I should have taken care of. So I guess I should have set about 100 thousand other variables to nothing just to catch this one case.
 
Last edited:
@jwcolby54 I guess your openargs class only replicates the built in functionality since you haven't been able to provide any reason I might want to invest the time to use it.
 
@jwcolby54 I guess your openargs class only replicates the built in functionality since you haven't been able to provide any reason I might want to invest the time to use it.
LOL, it is not my job to provide any reason for you to invest the time to use it. We all tread the path we tread on this earth. I have explained in some detail what a framework is, what mine does, and how this specific tiny little part of my framework contributes to the whole. You apparently have no interest in such things. You are intentionally baiting it seems. You are you and I am, thankfully, not. A little baiting of my own! :ROFLMAO:

In any event I will place you on my ignore list.

If I can figure out how to do that.
 
In any event I will place you on my ignore list.
Good move since you are no teacher. Teachers always answer honest questions respectfully. Just FYI. No novice is following this conversation and the experts all know what a framework is and all of them practice strong design principles but thanks for the lesson anyway.

My takeaway is - your openargs class adds nothing to Access that doesn't already exist.
 
No you do not. You do not destroy anything. All you are doing is releasing a pointer. But if this makes you feel better continuing doing it.

If you believe that VBA does not have a trusted clean up, I say prove it.
All this discussion about setting objects to Nothing is usually a complete waste of time. What you think you are doing is not really doing anything. You are simply releasing a pointer. You are not triggering "garbage collection" or memory clean up. VBA takes care of that.

There are times to close open connections and there are a few times to set objects to nothing. But you are really better off understanding the exceptions instead of thinking you are doing something by setting everything to nothing. At the most I set objects to nothing 1% of the time, but it is for a specific reason. Some of this is described here.



People find it easier to just set all objects to nothing based on an urban myth, than trying to understand when and why.

You can disagree with this, and again I say prove it. Show some cases where the code fails when not setting something to nothing. I can demonstrate some of those cases.

I the last twenty years of actively posting stuff on forums, I am sure I have posted 100 of thousands of lines of vba code, 1000s of example dbs, 100s of class modules and rarely if ever set an object to nothing. Only once did someone come back and say the code failed. And this case falls into one of those exact cases explained in the article that I should have taken care of. So I guess I should have set about 100 thousand other variables to nothing just to catch this one case.
Funny you should mention that. I understand "last pointer" thing but IMO the vast majority of devs do not. The man asked a simple question, I gave a simple answer. I am (or more correctly was) deep into classes and frameworks, where objects loaded other objects, kept pointers to forms, passed those pointers (and others) into the classes they were opening. I absolutely did have issues when I didn't intentionally clean things up. I had forms not closing. I had Access not closing because something was hanging out that the Access couldn't shut down. Not setting that "last pointer" to nothing can and does cause issues. And so I do, intentionally, with malice and forethought, religiously clean up behind myself.

And if you don't, or think I am silly... <shrug> It's sad there is no shrug emoji. I thought I had seen one.

In any event I was just in the process of starting a thread about the so called garbage collector in VBA. It is not easy to get it all pasted in, and keep the
Code:
thing around everything. But I am trying!

I expect a lively discussion. I probably will not participate since this is just an academic interest to me, and at the moment I am doing other things.
 
Good move since you are no teacher. Teachers always answer honest questions respectfully. Just FYI. No novice is following this conversation and the experts all know what a framework is and all of them practice strong design principles but thanks for the lesson anyway.

My takeaway is - your openargs class adds nothing to Access that doesn't already exist.
Now do me a favor and (since you are such a great instructor) tell me how to ignore your posts?
 
Good move since you are no teacher. Teachers always answer honest questions respectfully. Just FYI. No novice is following this conversation and the experts all know what a framework is and all of them practice strong design principles but thanks for the lesson anyway.

My takeaway is - your openargs class adds nothing to Access that doesn't already exist.
533 views as of this instant. But hey. I have no metrics to tell me how many of those views are novices etc, or who follows things.

And you are right I am no teacher. I have answered you same "issue" over and over and you either don't understand or choose not to understand.

In the end I am just a guy who was unfortunate enough to run into and annoy you in my threads:sick:. It has been mildly amusing if nothing else. And it has been, mostly, nothing else.

You are an "acknowledged expert" (and yes @NauticalGent I am using the quotes intentionally) here but TBH you haven't contributed anything useful to my threads. EVER that I can remember.

Are we having fun yet?
 
Well, isn't it a form of garbage collection?
I am setting up a discussion on how VBA's garbage collection works. Is it a "garbage collector"? Who really cares. What does that really mean? Such an existential discussion we launch into. In the end it takes care of releasing the memory used for our objects when we release them. The generic term for that is garbage collection.
 
I am setting up a discussion on how VBA's garbage collection works. Is it a "garbage collector"? Who really cares. What does that really mean? Such an existential discussion we launch into. In the end it takes care of releasing the memory used for our objects when we release them. The generic term for that is garbage collection.
The thread on "garbage collection on VBA" is up there now.
 
You are an "acknowledged expert" (and yes @NauticalGent I am using the quotes intentionally) here but TBH you haven't contributed anything useful to my threads. EVER that I can remember.
Except I gave you that cool code that fixes a broken seed.
 
No you do not. You do not destroy anything. All you are doing is releasing a pointer. But if this makes you feel better continuing doing it.

If you believe that VBA does not have a trusted clean up, I say prove it.
All this discussion about setting objects to Nothing is usually a complete waste of time. What you think you are doing is not really doing anything. You are simply releasing a pointer. You are not triggering "garbage collection" or memory clean up. VBA takes care of that.

There are times to close open connections and there are a few times to set objects to nothing. But you are really better off understanding the exceptions instead of thinking you are doing something by setting everything to nothing. At the most I set objects to nothing 1% of the time, but it is for a specific reason. Some of this is described here.

People find it easier to just set all objects to nothing based on an urban myth, than trying to understand when and why.

You can disagree with this, and again I say prove it. Show some cases where the code fails when not setting something to nothing. I can demonstrate some of those cases.

I the last twenty years of actively posting stuff on forums, I am sure I have posted 100 of thousands of lines of vba code, 1000s of example dbs, 100s of class modules and rarely if ever set an object to nothing. Only once did someone come back and say the code failed. And this case falls into one of those exact cases explained in the article that I should have taken care of. So I guess I should have set about 100 thousand other variables to nothing just to catch this one case.
Thanks for contributing to the discussion. I perfectly know I don't "destroy" anything, and it's just a pointer release. "Destroy" is just a word I often use in place of "releasing a pointer" because I find it more satisfying, and I'm sorry if you felt offended by that. Are you a member of some radical association against the use of "set to nothing"? Otherwise, I can't explain such vehemence against a habit of mine that, in the worst case scenario, has no consequence and doesn't hurt anyone. More specifically - yes, it occurred to me in the past. I had malfunctionings and, in a few cases, a crash of the application because I didn't destroy - sorry, released the pointers of - some objects. Can I prove it? Of course not, I can't recreate the exact scenario. Perhaps I could prove it using Windows objects like timers, but I don't feel like spending time on such a minor issue. And I don't see no reason to abandon this habit, which takes me literally seconds, just to risk another disaster which would take me hours to debug and solve. It's called "preventive programming". Is it useless, a waste of time? Yes, maybe, I agree. But it's MY developing time we're talking about, it doesn't harm, and certainly doesn't deserve such a rude reaction.
 
Otherwise, I can't explain such vehemence against a habit of mine that, in the worst case scenario, has no consequence and doesn't hurt anyone. More specifically - yes, it occurred to me in the past. I had malfunctionings and, in a few cases, a crash of the application because I didn't destroy - sorry, released the pointers of - some objects. Can I prove it? Of course not, I can't recreate the exact scenario.
Sorry if my rant seemed directed to you, it was not meant to be. It really to all the other people that repeat this information and state that setting objects to nothing is a requirement and the the solution for all our coding ills. Trust me you will see it on this site often. As I said if someone wants to wear belts and suspenders and it makes them feel better than have at it.

I will not tell a novice user that is the solution. I will tell them to try to learn when you set objects to nothing and when not to. (Circular references, implicit circular references, etc). There are also similar social myths I see people repeat with these blanket solutions instead of understanding the real issue.

But I do have an issue (because there are a lot of novice users reading things on this site that are influenced with what you post) when people propagate myths. When people suggest things like Access does not have trusted "garbage clean up" and therefore setting every object to nothing is something we should be doing. Or that somehow they are "cleaning up" after themselves where in other languages this does have a meaning.
 
I still don't see your point. Releasing pinters takes seconds. Trying to avoid/looking for circular references, implicit circular references etc. can take A LOT of time and experience. What's the added value in it? What's SO wrong in setting a pointer to nothing?
 
Sorry if my rant seemed directed to you, it was not meant to be. It really to all the other people that repeat this information and state that setting objects to nothing is a requirement and the the solution for all our coding ills. Trust me you will see it on this site often. As I said if someone wants to wear belts and suspenders and it makes them feel better than have at it.

I will not tell a novice user that is the solution. I will tell them to try to learn when you set objects to nothing and when not to. (Circular references, implicit circular references, etc). There are also similar social myths I see people repeat with these blanket solutions instead of understanding the real issue.

But I do have an issue (because there are a lot of novice users reading things on this site that are influenced with what you post) when people propagate myths. When people suggest things like Access does not have trusted "garbage clean up" and therefore setting every object to nothing is something we should be doing. Or that somehow they are "cleaning up" after themselves where in other languages this does have a meaning.
The issue with this is that it does take a lot of experience, which you absolutely have (but the novice absolutely does not have), to actually know when it will cause an issue and when it won't and if you get it wrong things do not work right, and trying to figure out why things are not working right can take a lot of time. Or in fact for the novice they may never figure out what is going wrong.

So while you are technically correct, and you are technically correct, just cleaning up each and every pointer to every object dimensioned takes little time and absolutely can and does prevent some issue some where. Further, classes give us the close event specifically for the purpose of performing cleanup, which strongly implies that MS encourages this practice. It is accepted practice by the vast majority of even expert developers, myself included, to just clean up behind myself. In fact it is accepted practice in pretty much every language environment!

And so I absolutely do that. Because I have so many classes just instantiated and destroyed automatically, passing pointers to objects back and forth, using WithEvents routinely, I absolutely have run into this very problem and figuring out why was an absolute nightmare. And I do know the why of what I am doing!

And... I have no problem with you (and I) teaching what is behind this practice, what we are actually fixing when we do this. Knowledge is a good thing.
 
Last edited:
I still don't see your point. Releasing pinters takes seconds. Trying to avoid/looking for circular references, implicit circular references etc. can take A LOT of time and experience. What's the added value in it? What's SO wrong in setting a pointer to nothing?
Is there any place I say I have a problem with setting an object variable to nothing? I do not think I suggested that people should not do this. I am not criticizing you for doing it.

Again, I say it every time. If globally doing this makes you feel better than have at it. But I have issue when I see people post things and they do not at least try to explain when and why you have too and what the real benefits and risks are. If people sells this for what it is, I am fine with that, but rarely is that done. It is always sold as being high risk if you do not, that it is a very common problem, and you are only ever safe setting all objects to nothing. And this is somehow the way to "manage memory"

If you want to tell a novice user that they should set all objects variables to nothing because there are very rare cases when they might have to and it is easier to do that then understand those rare cases, then I am fine if people sell it that way. It always get sold as "you have to set all objects to nothing", or there is some high risk if you do not. I am not going to criticize anyone for setting objects to nothing, I never have. I will criticize those on the forum that say things like "your code is failing because you did not set your objects to nothing" when the issue is clearly not related and highly unlikely. I do criticize when people suggest that there are problems with access reference counting and cleanup, when there is nothing to support that and that only causes confusion.
 
What's SO wrong in setting a pointer to nothing?
There's nothing wrong with doing this, but let's you have a circular reference between ObjectA and ObjectB, so they each hold a reference to the other, and you add them both to CollectionC. In this case setting CollectionC to Nothing does not cause ObjectA and ObjectB to automatically go out of scope, nor does enumerating the collection and setting each of its member items to nothing. To MajP's point, you need to explicitly deal with the circular reference.

A common pattern would be for ObjectA, ObjectB, and the owner of CollectionC to implement an interface (maybe IDisposable, exposing a Dispose method) enabling each instance to encapsulate it's own custom deconstruction, and making it available for outside consumers to call. Then, enumerate the collection, check if the item implements IDisposable using TypeOf, and if so, call that method.

So your interface definition (this is a class called IDisposble) looks like...
Code:
Public Sub Dispose()
End Sub
Then ObjectA does...
Code:
Implements IDisposable

Private Sub IDisposable_Dispose()
    Set m_obj_B = nothing
End Sub
...ObjectB does...
Code:
Implements IDisposable

Private Sub IDisposable_Dispose()
    Set m_obj_A = nothing
End Sub
... and finally, if FormD created CollectionC, it does...
Code:
Private Sub Form_Unload(Cancel as Integer)
    Dim obj As Object

    For Each obj in CollectionC
        DisposeOf obj
    Next
    Set m_Col_C = Nothing
End Sub
... which assumes the presence of a public global method...
Code:
Public Sub DisposeOf(obj As Object)
    Dim idp As IDisposable
   
    If TypeOf obj Is IDisposable Then
        Set idp = obj
        idp.Dispose
    End If
    Set obj = Nothing
End Sub
 
It always get sold as "you have to set all objects to nothing",
@MajP This is the exact reason I started setting all variables to nothing. Some people without having the correct understanding, start "Teaching" ((and yes @jwcolby54 I am using the quotes intentionally) their wrong methods of programing and saying vba doesn't clean after itself or such, and we follow them blindly, without being told the whys and whens. And their reasons be like : Novic users don't understand.

it does take a lot of experience, which you have (but the novice absolutely does not have), to actually know when it will cause an issue and when it won't

I really appreciate you for bringing it up, for the way you put it out and specially forthe link.
Thanks @MajP.

So while you are technically correct, and you are technically correct, just cleaning up each and every pointer to every object dimensioned takes little time and absolutely can and does prevent some issue some where.
@jwcolby54 Taking time or not is not the problem. The important point is to learn to progrom correctly. Not to put a lot of walls and doors around our code for ifs and maybes. I prefer to be told why it's done. Not because you don't understand put a =nothing to everything.
 

Users who are viewing this thread

  • Back
    Top Bottom