Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / April 2005

Tip: Looking for answers? Try searching our database.

Objects not Destroying

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 29 Apr 2005 21:36 GMT
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
Scott M. - 29 Apr 2005 21:52 GMT
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.

> 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
[quoted text clipped - 30 lines]
> Thank you,
> Richard
Richard - 29 Apr 2005 23:16 GMT
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("ServiceIssueDetailIssueID").ToString) = False
Then
           Itinerary.Add(Session("ServiceIssueDetailIssueID").ToString,
Session("ServiceIssueDetailIssueDescription").ToString)
       End If

   End Sub

> 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
[quoted text clipped - 42 lines]
> > Thank you,
> > Richard
Scott M. - 30 Apr 2005 00:02 GMT
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.

> Hi Scott, thanks for your reply. I'm not caching the sortedlist such as in
> a
[quoted text clipped - 82 lines]
>> > Thank you,
>> > Richard

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.