Cassio Posted September 23, 2003 Posted September 23, 2003 Hi, I´d like to know if theres any diference between these two aproaches: 1. Private cn as SQLConnection Private Sub Sub1() cn = New SQLConnection(connectionstring) 'Code here cn.close End Sub Private Sub Sub2() cn = New SQLConnection(connectionstring) 'Code here cn.close End Sub 2. Private Sub Sub1() Dim cn as SQLConnection cn = New SQLConnection(connectionstring) 'Code here cn.close End Sub Private Sub Sub2() Dim cn as SQLConnection cn = New SQLConnection(connectionstring) 'Code here cn.close End Sub I guess theres no diference, since I instanciate the cn object inside the procedures, right? Thanks. Quote Stream of Consciousness (My blog)
*Experts* mutant Posted September 23, 2003 *Experts* Posted September 23, 2003 There is a difference, even though you initialize the instance inside of a sub/function that variable itself is global to the class and when initializing you are crating an instance for that variable. Quote
Cassio Posted September 24, 2003 Author Posted September 24, 2003 Does the first method consume more memory? Quote Stream of Consciousness (My blog)
Mehyar Posted September 24, 2003 Posted September 24, 2003 I would say yes since the variable is there as long the class is running. While in the second it is only declared when the sub is called and then disposed when it is done Quote Dream as if you'll live forever, live as if you'll die today
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.