Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

How does VB handle memory in this situation?

Status
Not open for further replies.

boflexson

Programmer
Oct 16, 2001
74
US
If I have a procedure as follows:
Private sub DoSomethingWithMe(byref objMyThing as clsCool)

objMyThing.IsCool = True

End Sub

Does VB Increment the link counter in the object.
And if so does it decrement it on exit as well?

Or should the procedure be like this?
Private sub DoSomethingWithMe(byref objMyThing as clsCool)

objMyThing.IsCool = True
Set objMyThing = Nothing

End Sub

-Bo Flexson
 
I think that the answer to your question is dependant on the object, and how the Object was created. (By Created here, I mean compiled.) Check out the Knowledge Base in VB6's "Help", and search for "Instancing for Classes Provided by ActiveX Components." They discuss the various compiler options, and how they affect memory usage etc.

Hunter
 
I'm not sure why a subroutine call would increase a link counter on an object parameter.

You have a private sub here, so I can't imagine how the Sub gets called from another thread.

Are you playing any of the games that might yield extra threads for your VB program or something?

In other words, if this is a normal Sub within a VB .EXE or in-process server (.DLL, .OCX) the answer is "no, you don't want to break the object reference." You'll be breaking it for the calling logic.

Was this question prompted by some symptom you have encountered? If so, try describing it and maybe somebody will have a solution.
 
ok,
If I have the following code.

Private Sub DoSomethingWithMe(ByRef objMyThing As clsCool)

objMyThing.IsCool = True
Set objMyThing = Nothing

End Sub

It does break the reference in the calling procedure.
But If I change it to

Private Sub DoSomethingWithMe(ByVal objMyThing As clsCool)

objMyThing.IsCool = True
Set objMyThing = Nothing

End Sub

It does not.
In this case VB must make a new reference to the object, thereby incrementing the reference counter. In this case does VB De-Increment that counter if I leave the set = nothing call out?
I simply need to completly understand when my objects are cleared from memory.

-Bo Flexson

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top