|
-
Dec 14th, 2001, 05:20 AM
#1
Thread Starter
Hyperactive Member
Correct me if i'm wrong...
Hi,
Consider the following code:
VB Code:
Set oRs = CallMethodToGetRecordset()
Set oRs1 = oRs
Set oRs = Nothing
All along I'v been under the impression that setting oRs to Nothing within the scope would set oRs1 also to Nothing. But today I see that oRs1 has its records in place! I wondor how...
Is it something like this?
The statement "Set oRs1 = oRs" will set oRs1 to the Base Address of oRs. If I set the base address of oRs to Nothing, oRs1 is still pointing to the location with the values.
However, when I move oRs, oRs1 is also getting moved. When i close oRs, oRs1 is also getting closed!
Can some one pls explain...
- Jemima.
-
Dec 14th, 2001, 05:25 AM
#2
Hyperactive Member
this is like two pointers pointing to same location.
oRs1 is pointing to oRs that is why it gets moved when you move Ors. but when you set ors1 to nothing only reference of ors gets broken and memory is freed. ors is still there!
it is like
ors1->ors->some records
-
Dec 14th, 2001, 05:31 AM
#3
PowerPoster
hi
As far as I know the technique is used in case of Disconected recordsets wherein u need to ease the server load
How it works actually in the background - I think the same what u have written - cant explained it otherwise
-
Dec 14th, 2001, 05:37 AM
#4
While writing a Clone method in my class module which
contain a objects called say oX of type X, I had got the same
problem.
I solved it by creating a new local copy of object X in Clone method and assigned the properties of oX to X using '='
I think the problem in your case can be solved by creating
an intermediate for marshalling purpose, so that
any changes made by new object should not reflect in the old
object
Hope this won't complicates your matter
- Somnath
-
Dec 14th, 2001, 05:57 AM
#5
Thread Starter
Hyperactive Member
No Abhid... i don't still get the point... Yes, setting an object to nothing releases the memory taken by the object, a recordset here, then where is oRs1 pointing? Directly to the base address in memory? In that case, how about Moving the recordset?
Thanks, somnath but i don't have a practical situation right now, jus curious to know.
Thanks guys.
Jemima.
-
Dec 14th, 2001, 06:15 AM
#6
Well ...
Let's put it this way:
The OpenRecordset method creates an object of type Recordset and passes its reference back. You have a recordset object in which you store this reference. That goes something like:
Set rs1 = db.OpenRecordset("...")
(I guess here the record values are loaded into the memory. And I missed another point: You are using your own method to create and pass a recordset object. It's got to be only a reference, not an actual set of values!)
Here rs1 only contains a reference to the RecordSet object created by OpenRecordset.
Now you create another recordset object rs1, and assign the value of rs1 to rs2. So you assign the reference to the recordset to rs2.
Now when you take any actions that affect the recordset, such as moving or closing, since they will affect the recordset, they will be reflected in both rs1 and rs2.
However, setting rs1 to Nothing will only free up this reference object. The recordset is still in the memory, and its address has already been stored to the rs2 variable. So, rs2 still maintains its link to the recordset.
I think that's why you need to Close the recordset before setting it to Nothing. Close ensures that the recordset is actually removed from the memory, and setting a recordset variable to Nothing will make sure that the reference to that memory location has been removed. Sort of like the garbage collection in Java.
mmmmm.... I think that's pretty much how it works. Or should work.

.
Last edited by honeybee; Dec 14th, 2001 at 06:28 AM.
-
Dec 14th, 2001, 06:17 AM
#7
Hyperactive Member
when you use Set to assign an object reference to a variable, no copy of the object is created for that variable. Instead, a reference to the object is created
Found this in MSDN. I think this means even after
Set oRs = CallMethodToGetRecordset()
Set oRs1 = oRs
ors1 still refers to recordset returned by method and not to ors.
-
Dec 14th, 2001, 06:32 AM
#8
Thread Starter
Hyperactive Member
Hi Hb.
Yeah getting it now... I think thats what abhid was telling all the while! Tuk some time to get in here, though! Thanks.
So its really good habits to close a recordset and then release it! Will keep that in mind.
You've enlightened me! Thanks 
Jemima.
-
Dec 14th, 2001, 06:35 AM
#9
Well ...
Gee, thanks.
I was afraid I would lose track of the discussion. It was such a long post on such a complex topic!! Thank God it came out alright.

.
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
|