|
-
Aug 8th, 2003, 03:17 PM
#1
Thread Starter
Hyperactive Member
Address Question
I'm wondering if anyone can answer these pretty basic OOP questions dealing with classes and memory addresses..
Public Class TestClass
Public s As String
End Class
Dim X As New TestClass
X.s = "Test 1"
Dim Y As TestClass = X
Dim Z As TestClass = X
Am I correct in saying X holds the original copy of TestClass and Y and Z are just Pointers that point to the copy of X?
So if I...
Y.s = "Test 2"
That changes the original "s" in element X right so now (X,Y,Z).s all equal "Test 2"
Now if I do a
X = Nothing
Y.s and Z.s still show the "Test 2" but now where has the Original copy that was in X gone? Are Y and Z still just pointers or does one of them now contain the original ? Im wondering because if X is no longer a object, Y and Z shouldn't be able to access it anymore right??
I'm confused..
-
Aug 8th, 2003, 04:24 PM
#2
Try it:
VB Code:
Dim X As New TextBox
X.Text = "Test 1"
Dim Y As TextBox = X
Dim Z As TextBox = X
MsgBox(String.Format("Y='{0}' Z='{1}'", Y.Text, Z.Text))
Y.Text = "Test 2"
MsgBox(String.Format("X='{0}' Z='{1}'", X.Text, Z.Text))
X = Nothing
MsgBox(String.Format("Y='{0}' Z='{1}' X='{2}'", Y Is Nothing, Z Is Nothing, X Is Nothing))
I think the answer is that x,y, and z are all just pointers to the address where the class belongs. The 'original copy' is seperate and keeps track of who is referencing it and is not set to nothing, itself, until all references to it are gone or set to nothing.
-
Aug 8th, 2003, 05:16 PM
#3
Thread Starter
Hyperactive Member
Ah thanks again Edneeis, that's clears up alot.. So I guess I gotta keep tight tabs on all the pointers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|