Avatar of shacho
shacho

asked on 

Best Practice Memory Question Regarding Functions that Return Object References

If I have a function that returns an object reference, such as this...

Sub GetRef()
    MsgBox ObjRef.Name
End Sub

Function ObjRef() as Object
    Set ObjRef = MyObj
End Function

What happens to that allocated memory space when the calling routine terminates?  Is it automatically destroyed?  Is it better to do something like this?

Sub GetRef()
    Dim OR as Object
    Set OR = ObjRef()
    MsgBox OR.Name
    Set OR = Nothing
End Sub

Mike
Visual Basic ClassicMicrosoft Excel

Avatar of undefined
Last Comment
shacho
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of shacho
shacho

ASKER

Thanks Kevin!

Mike
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo