HighTechTalks DotNet Forums  

Objects not Destroying

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss Objects not Destroying in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Richard
 
Posts: n/a

Default Objects not Destroying - 04-29-2005 , 04:36 PM






I'm running into a problem with objects not destroying when the browser
closes and is reopened. I have a custom collection that is declared public in
a module, and instantiated elsewhere (linkbutton click event). The collection
works fine, but when I close the browser and then I restart the web app, the
collection is still instantiated and contains alll of the items it had before
the browser was closed!

I was under the impression that once the browser closes, all objects go with
it. What I've been doing to "fix" this is in the main.aspx's pageload event,
checking if the object is not nothing, and clearing it if it is. This is not
limited to custom collections; I have a sortedlist class that is also still
"active" once the browser closes and then is restarted:

If Itinerary Is Nothing Then
Itinerary = New SortedList
Else
Itinerary.Clear()
Itinerary = Nothing
Itinerary = New SortedList
End If

Other than the above method, how can I ensure that my objects die when the
user clicks on the close button on the browser?

Thank you,
Richard

Reply With Quote
  #2  
Old   
Scott M.
 
Posts: n/a

Default Re: Objects not Destroying - 04-29-2005 , 04:52 PM






The browser has absolutely nothing to do with it. The server has no way of
knowing when a browser closes. In fact, by the time the browser even gets
the page, the server has already finished its processing and has
disconnected from the client.

All of your object variables will fall out of scope when the page finishes
its server-side processing. The objects themselves will remain in memory
until the Garbage Collector cleans up the heap.

Your problem sounds more like your are caching some results somewhere and
the server is reusing those results for new page requests.


"Richard" <Richard (AT) discussions (DOT) microsoft.com> wrote

Quote:
I'm running into a problem with objects not destroying when the browser
closes and is reopened. I have a custom collection that is declared public
in
a module, and instantiated elsewhere (linkbutton click event). The
collection
works fine, but when I close the browser and then I restart the web app,
the
collection is still instantiated and contains alll of the items it had
before
the browser was closed!

I was under the impression that once the browser closes, all objects go
with
it. What I've been doing to "fix" this is in the main.aspx's pageload
event,
checking if the object is not nothing, and clearing it if it is. This is
not
limited to custom collections; I have a sortedlist class that is also
still
"active" once the browser closes and then is restarted:

If Itinerary Is Nothing Then
Itinerary = New SortedList
Else
Itinerary.Clear()
Itinerary = Nothing
Itinerary = New SortedList
End If

Other than the above method, how can I ensure that my objects die when the
user clicks on the close button on the browser?

Thank you,
Richard



Reply With Quote
  #3  
Old   
Richard
 
Posts: n/a

Default Re: Objects not Destroying - 04-29-2005 , 06:16 PM



Hi Scott, thanks for your reply. I'm not caching the sortedlist such as in a
session object, so how can it be reused by the server?

It's declared in a module:
Module mdlGeneral

Public Itinerary As SortedList

End Module

Then it is instantiated and used in a click event:
Private Sub btnAddToItinerary_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnAddToItinerary.Click

'Create the object if necessary.
If Itinerary Is Nothing Then
Itinerary = New SortedList
End If

'Look for the issue id first. Add it if not already in the sortedlist.
If
Itinerary.ContainsKey(Session("ServiceIssueDetailI ssueID").ToString) = False
Then
Itinerary.Add(Session("ServiceIssueDetailIssueID") .ToString,
Session("ServiceIssueDetailIssueDescription").ToSt ring)
End If

End Sub

"Scott M." wrote:

Quote:
The browser has absolutely nothing to do with it. The server has no way of
knowing when a browser closes. In fact, by the time the browser even gets
the page, the server has already finished its processing and has
disconnected from the client.

All of your object variables will fall out of scope when the page finishes
its server-side processing. The objects themselves will remain in memory
until the Garbage Collector cleans up the heap.

Your problem sounds more like your are caching some results somewhere and
the server is reusing those results for new page requests.


"Richard" <Richard (AT) discussions (DOT) microsoft.com> wrote in message
news:71C59AAC-9FD7-406A-B724-75C4A4BFA914 (AT) microsoft (DOT) com...
I'm running into a problem with objects not destroying when the browser
closes and is reopened. I have a custom collection that is declared public
in
a module, and instantiated elsewhere (linkbutton click event). The
collection
works fine, but when I close the browser and then I restart the web app,
the
collection is still instantiated and contains alll of the items it had
before
the browser was closed!

I was under the impression that once the browser closes, all objects go
with
it. What I've been doing to "fix" this is in the main.aspx's pageload
event,
checking if the object is not nothing, and clearing it if it is. This is
not
limited to custom collections; I have a sortedlist class that is also
still
"active" once the browser closes and then is restarted:

If Itinerary Is Nothing Then
Itinerary = New SortedList
Else
Itinerary.Clear()
Itinerary = Nothing
Itinerary = New SortedList
End If

Other than the above method, how can I ensure that my objects die when the
user clicks on the close button on the browser?

Thank you,
Richard




Reply With Quote
  #4  
Old   
Scott M.
 
Posts: n/a

Default Re: Objects not Destroying - 04-29-2005 , 07:02 PM



Why are you declaring it in a module? That's your problem. Itinerary is
never going to be nothing as long as the web application is running. Just
declare and instantiate it in the web page. If you need to persist it
between different pages consider caching it or passing it between pages.


"Richard" <Richard (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi Scott, thanks for your reply. I'm not caching the sortedlist such as in
a
session object, so how can it be reused by the server?

It's declared in a module:
Module mdlGeneral

Public Itinerary As SortedList

End Module

Then it is instantiated and used in a click event:
Private Sub btnAddToItinerary_Click(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles btnAddToItinerary.Click

'Create the object if necessary.
If Itinerary Is Nothing Then
Itinerary = New SortedList
End If

'Look for the issue id first. Add it if not already in the
sortedlist.
If
Itinerary.ContainsKey(Session("ServiceIssueDetailI ssueID").ToString) =
False
Then
Itinerary.Add(Session("ServiceIssueDetailIssueID") .ToString,
Session("ServiceIssueDetailIssueDescription").ToSt ring)
End If

End Sub

"Scott M." wrote:

The browser has absolutely nothing to do with it. The server has no way
of
knowing when a browser closes. In fact, by the time the browser even
gets
the page, the server has already finished its processing and has
disconnected from the client.

All of your object variables will fall out of scope when the page
finishes
its server-side processing. The objects themselves will remain in memory
until the Garbage Collector cleans up the heap.

Your problem sounds more like your are caching some results somewhere and
the server is reusing those results for new page requests.


"Richard" <Richard (AT) discussions (DOT) microsoft.com> wrote in message
news:71C59AAC-9FD7-406A-B724-75C4A4BFA914 (AT) microsoft (DOT) com...
I'm running into a problem with objects not destroying when the browser
closes and is reopened. I have a custom collection that is declared
public
in
a module, and instantiated elsewhere (linkbutton click event). The
collection
works fine, but when I close the browser and then I restart the web
app,
the
collection is still instantiated and contains alll of the items it had
before
the browser was closed!

I was under the impression that once the browser closes, all objects go
with
it. What I've been doing to "fix" this is in the main.aspx's pageload
event,
checking if the object is not nothing, and clearing it if it is. This
is
not
limited to custom collections; I have a sortedlist class that is also
still
"active" once the browser closes and then is restarted:

If Itinerary Is Nothing Then
Itinerary = New SortedList
Else
Itinerary.Clear()
Itinerary = Nothing
Itinerary = New SortedList
End If

Other than the above method, how can I ensure that my objects die when
the
user clicks on the close button on the browser?

Thank you,
Richard






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.