msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question about memory allocation

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
boaz



Joined: 04 Oct 2007
Posts: 259

PostPosted: Wed Sep 17, 2003 6:54 pm    Post subject: Question about memory allocation Reply with quote

Hi,

Please take a look at the following codes:

10 Dim My_Recordset As ADODB.Recordset
20 Set My_Recordset = New ADODB.Recordset
30 My_Recordset.Open [This and That]
40 My_Recordset.Close
50 Set My_Recordset = New ADODB.Recordset
60 My_Recordset.Open [This and That]
70 My_Recordset.Close
80 Set My_Recordset = Nothing

I have 2 "Set My_Recordset = New ADODB.Recordset" statements.

Would you tell me what kind of problem (if any) I will get please?



--
>There is no answer.
> There has not been an answer.
> There will not be an answer.
> That IS the answer!

Archived from group: microsoft>public>vb>enterprise
Back to top
View user's profile Send private message
Val



Joined: 04 Oct 2007
Posts: 3

PostPosted: Thu Sep 18, 2003 3:20 am    Post subject: RE:Question about memory allocation Reply with quote

>-----Original Message-----
>Hi,
>
>Please take a look at the following codes:
>
>10 Dim My_Recordset As ADODB.Recordset
>20 Set My_Recordset = New ADODB.Recordset
>30 My_Recordset.Open [This and That]
>40 My_Recordset.Close
>50 Set My_Recordset = New ADODB.Recordset
>60 My_Recordset.Open [This and That]
>70 My_Recordset.Close
>80 Set My_Recordset = Nothing
>
>I have 2 "Set My_Recordset = New ADODB.Recordset"
statements.
>
>Would you tell me what kind of problem (if any) I will
get please?
>
>
>
>--
>>There is no answer.
>> There has not been an answer.
>> There will not be an answer.
>> That IS the answer!
>
>
>.
>

No problem (that I know of). After line 50, you loose the
reference to the first Recordset object, but this isn't a
problem for VB. As soon as VB detects that an object isn't
referenced anymore, it will destroy that object and
reclaim the memory allocated for it. Although you don't
need to explicitly set the variable My_Recordset to
Nothing, calling Close when you've finished with the
Recordset is necessary in order to avoid resource leaks.
HTH,
Val
Back to top
View user's profile Send private message
boaz



Joined: 04 Oct 2007
Posts: 259

PostPosted: Thu Sep 18, 2003 2:10 pm    Post subject: Re: RE:Question about memory allocation Reply with quote

Thanks for the info. I have another question.

If I add the following line, will it create any problem?

45 Set My_Recordset = Nothing



"Val" wrote in message$e6c0d570$a301280a@phx.gbl...
>
> >-----Original Message-----
> >Hi,
> >
> >Please take a look at the following codes:
> >
> >10 Dim My_Recordset As ADODB.Recordset
> >20 Set My_Recordset = New ADODB.Recordset
> >30 My_Recordset.Open [This and That]
> >40 My_Recordset.Close
> >50 Set My_Recordset = New ADODB.Recordset
> >60 My_Recordset.Open [This and That]
> >70 My_Recordset.Close
> >80 Set My_Recordset = Nothing
> >
> >I have 2 "Set My_Recordset = New ADODB.Recordset"
> statements.
> >
> >Would you tell me what kind of problem (if any) I will
> get please?
> >
> >
> >
> >--
> >>There is no answer.
> >> There has not been an answer.
> >> There will not be an answer.
> >> That IS the answer!
> >
> >
> >.
> >
>
> No problem (that I know of). After line 50, you loose the
> reference to the first Recordset object, but this isn't a
> problem for VB. As soon as VB detects that an object isn't
> referenced anymore, it will destroy that object and
> reclaim the memory allocated for it. Although you don't
> need to explicitly set the variable My_Recordset to
> Nothing, calling Close when you've finished with the
> Recordset is necessary in order to avoid resource leaks.
> HTH,
> Val
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 2047

PostPosted: Thu Sep 18, 2003 2:11 pm    Post subject: Re: RE:Question about memory allocation Reply with quote

"boaz" wrote in message@TK2MSFTNGP09.phx.gbl
> Thanks for the info. I have another question.
>
> If I add the following line, will it create any problem?
>
> 45 Set My_Recordset = Nothing

No, it will not create a problem. Since line 50 sets 'My_Recordset' to
something else it is not necessary but it does no harm beyond possibly
requiring a few extra CPU cycles during execution.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group