Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Memory Leaks


Message #1 by rg1@h... on Fri, 24 Aug 2001 16:54:13
Hi.



I have a question regarding memory leaks.



If I have Page1.asp that sets a reference to Object1, then Page1.asp 

encounters an error which will redirect to another page, thus bypassing 

the statement in Page1.asp to "Set Object1 = Nothing", will this cause a 

memory leak?



I could, before redirecting, use a "subDispose(ObjToDispose)" for each 

reference set, but wondered if this was necessary.



TIA.



Rita
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 27 Aug 2001 15:06:29 +1000
ASP is *supposed* to have it's own garbage collection. However, it is always

good programming practice to clean up after yourself explicitly.



That said, why redirect? I usually have something like this:



<%

Function fncWhatever( _

    )



    On Error Resume Next

    Const Proc = "fncWhatever"

    ...

    If Err.Number <> 0 then

        Call subErrorHandler(Err.Number, Proc, Err.Description)

    End If

End Function ' fncWhatever



Sub subErrorHandler( _

    ByVal strErrNum, _

    ByVal strErrSource, _

    ByVal strErrDescrip _

    )



    ' Clear existing Response Buffer

    Response.Clear

    Call subWritePageHeading()

    Call subWritePageBody()

    With Response

        .Write("<p>An error occured:<br>" & vbCrLf)

        .Write("Err Number: " & strErrNum<br>" & vbCrLf)

        .Write("Err Source: " & strErrSource<br>" & VbCrLf)

        .Write("</p>" & vbCrLf)

    End With

    Call subWritePageFooter()

    Response.Flush

    Response.End



End Sub ' subErrorHandler

%>



Of course, subErrorHandler would be in an include file that you just include

on every page...



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: <rg1@h...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Friday, August 24, 2001 4:54 PM

Subject: [asp_web_howto] Memory Leaks





: Hi.

:

: I have a question regarding memory leaks.

:

: If I have Page1.asp that sets a reference to Object1, then Page1.asp

: encounters an error which will redirect to another page, thus bypassing

: the statement in Page1.asp to "Set Object1 = Nothing", will this cause a

: memory leak?

:

: I could, before redirecting, use a "subDispose(ObjToDispose)" for each

: reference set, but wondered if this was necessary.

:

: TIA.

:

: Rita





Message #3 by Rita Greenberg <rg1@h...> on Mon, 27 Aug 2001 07:16:50 -0700
Thanks Ken for the sample code. I use something very similar except Redirect

instead of just calling the sub. The sub is the best way to go so everything

gets cleaned up.



Just a matter of interest. I noticed that you broke down the arguments

passed to subErrorhandler "Err.Number" and "Err.Description". I just pass

the whole Err object. Is your example more efficient?



Rita



-----Original Message-----

From: Ken Schaefer [mailto:ken@a...]

Sent: Sunday, August 26, 2001 10:06 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Memory Leaks





ASP is *supposed* to have it's own garbage collection. However, it is always

good programming practice to clean up after yourself explicitly.



That said, why redirect? I usually have something like this:



<%

Function fncWhatever( _

    )



    On Error Resume Next

    Const Proc = "fncWhatever"

    ...

    If Err.Number <> 0 then

        Call subErrorHandler(Err.Number, Proc, Err.Description)

    End If

End Function ' fncWhatever



Sub subErrorHandler( _

    ByVal strErrNum, _

    ByVal strErrSource, _

    ByVal strErrDescrip _

    )



    ' Clear existing Response Buffer

    Response.Clear

    Call subWritePageHeading()

    Call subWritePageBody()

    With Response

        .Write("<p>An error occured:<br>" & vbCrLf)

        .Write("Err Number: " & strErrNum<br>" & vbCrLf)

        .Write("Err Source: " & strErrSource<br>" & VbCrLf)

        .Write("</p>" & vbCrLf)

    End With

    Call subWritePageFooter()

    Response.Flush

    Response.End



End Sub ' subErrorHandler

%>



Of course, subErrorHandler would be in an include file that you just include

on every page...



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: <rg1@h...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Friday, August 24, 2001 4:54 PM

Subject: [asp_web_howto] Memory Leaks





: Hi.

:

: I have a question regarding memory leaks.

:

: If I have Page1.asp that sets a reference to Object1, then Page1.asp

: encounters an error which will redirect to another page, thus bypassing

: the statement in Page1.asp to "Set Object1 = Nothing", will this cause a

: memory leak?

:

: I could, before redirecting, use a "subDispose(ObjToDispose)" for each

: reference set, but wondered if this was necessary.

:

: TIA.

:

: Rita

Message #4 by rg1@h... on Mon, 27 Aug 2001 16:04:31
Ken, I just had a thought after going back to view your example 

subErrorHandler code. After the "Response.End", the error message is 

displayed on the screen. How does the control return to the line following 

the call to the error handled in fncWhatEver? Is there a button on the 

displayed error message screen that when the uses clicks it, control is 

returned? This to allow the error message to be displayed long enough for 

the user to see it.



Rita



> ASP is *supposed* to have it's own garbage collection. However, it is 

always

> good programming practice to clean up after yourself explicitly.

> 

> That said, why redirect? I usually have something like this:

> 

> <%

> Function fncWhatever( _

>     )

> 

>     On Error Resume Next

>     Const Proc = "fncWhatever"

>     ...

>     If Err.Number <> 0 then

>         Call subErrorHandler(Err.Number, Proc, Err.Description)

>     End If

> End Function ' fncWhatever

> 

> Sub subErrorHandler( _

>     ByVal strErrNum, _

>     ByVal strErrSource, _

>     ByVal strErrDescrip _

>     )

> 

>     ' Clear existing Response Buffer

>     Response.Clear

>     Call subWritePageHeading()

>     Call subWritePageBody()

>     With Response

>         .Write("<p>An error occured:<br>" & vbCrLf)

>         .Write("Err Number: " & strErrNum<br>" & vbCrLf)

>         .Write("Err Source: " & strErrSource<br>" & VbCrLf)

>         .Write("</p>" & vbCrLf)

>     End With

>     Call subWritePageFooter()

>     Response.Flush

>     Response.End

> 

> End Sub ' subErrorHandler

> %>

> 

> Of course, subErrorHandler would be in an include file that you just 

include

> on every page...

> 

> Cheers

> Ken

> 

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> From: <rg1@h...>

> To: "ASP Web HowTo" <asp_web_howto@p...>

> Sent: Friday, August 24, 2001 4:54 PM

> Subject: [asp_web_howto] Memory Leaks

> 

> 

> : Hi.

> :

> : I have a question regarding memory leaks.

> :

> : If I have Page1.asp that sets a reference to Object1, then Page1.asp

> : encounters an error which will redirect to another page, thus bypassing

> : the statement in Page1.asp to "Set Object1 = Nothing", will this cause 

a

> : memory leak?

> :

> : I could, before redirecting, use a "subDispose(ObjToDispose)" for each

> : reference set, but wondered if this was necessary.

> :

> : TIA.

> :

> : Rita

> 

> 

Message #5 by Kyle Burns <kburns@c...> on Mon, 27 Aug 2001 13:14:31 -0500
In many cases (should be always but doesn't work that way), the err object

is cleared when moving from proc to proc.  You're better off persisting the

information into arguments of your error handler.



=================================

Kyle M. Burns, MCSD

ECommerce Technology Manager

Centra Credit Union

kburns@c...



 



-----Original Message-----

From: Rita Greenberg [mailto:rg1@h...]

Sent: Monday, August 27, 2001 9:17 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Memory Leaks





Thanks Ken for the sample code. I use something very similar except Redirect

instead of just calling the sub. The sub is the best way to go so everything

gets cleaned up.



Just a matter of interest. I noticed that you broke down the arguments

passed to subErrorhandler "Err.Number" and "Err.Description". I just pass

the whole Err object. Is your example more efficient?



Rita



-----Original Message-----

From: Ken Schaefer [mailto:ken@a...]

Sent: Sunday, August 26, 2001 10:06 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Memory Leaks





ASP is *supposed* to have it's own garbage collection. However, it is always

good programming practice to clean up after yourself explicitly.



That said, why redirect? I usually have something like this:



<%

Function fncWhatever( _

    )



    On Error Resume Next

    Const Proc = "fncWhatever"

    ...

    If Err.Number <> 0 then

        Call subErrorHandler(Err.Number, Proc, Err.Description)

    End If

End Function ' fncWhatever



Sub subErrorHandler( _

    ByVal strErrNum, _

    ByVal strErrSource, _

    ByVal strErrDescrip _

    )



    ' Clear existing Response Buffer

    Response.Clear

    Call subWritePageHeading()

    Call subWritePageBody()

    With Response

        .Write("<p>An error occured:<br>" & vbCrLf)

        .Write("Err Number: " & strErrNum<br>" & vbCrLf)

        .Write("Err Source: " & strErrSource<br>" & VbCrLf)

        .Write("</p>" & vbCrLf)

    End With

    Call subWritePageFooter()

    Response.Flush

    Response.End



End Sub ' subErrorHandler

%>



Of course, subErrorHandler would be in an include file that you just include

on every page...



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: <rg1@h...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Friday, August 24, 2001 4:54 PM

Subject: [asp_web_howto] Memory Leaks





: Hi.

:

: I have a question regarding memory leaks.

:

: If I have Page1.asp that sets a reference to Object1, then Page1.asp

: encounters an error which will redirect to another page, thus bypassing

: the statement in Page1.asp to "Set Object1 = Nothing", will this cause a

: memory leak?

:

: I could, before redirecting, use a "subDispose(ObjToDispose)" for each

: reference set, but wondered if this was necessary.

:

: TIA.

:

: Rita





Message #6 by Rita Greenberg <rg1@h...> on Mon, 27 Aug 2001 12:43:21 -0700
Thanks Kyle, for the explanation.



-----Original Message-----

From: Kyle Burns [mailto:kburns@c...]

Sent: Monday, August 27, 2001 11:15 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Memory Leaks





In many cases (should be always but doesn't work that way), the err object

is cleared when moving from proc to proc.  You're better off persisting the

information into arguments of your error handler.



=================================

Kyle M. Burns, MCSD

ECommerce Technology Manager

Centra Credit Union

kburns@c...



 




  Return to Index