Advertisement

04.03.2008 at 05:49PM PDT, ID: 23294751
[x]
Attachment Details

Declaring and Disposing in VB.Net

Asked by grogo21 in Microsoft Visual Basic.Net, Programming for ASP.NET

Tags:

Hello, I have written a windows service in vb.net but I have a memory leak and I believe the issue is because I am not sure how to declare and dispose of variables and objects.  The service runs on a timer which elapses every 2 seconds.  It takes about 10 to 30 seconds to complete each run thru.  I currently have all of my code on a single page but it is split up into many sub routines and functions.  The service runs constantly and is never closed.

My question is basically how should I declare my variables and objects.
For instance, if I use a data reader in a sub should I declare it within the sub or globally at the top of the page.  Currently, I declare the data reader in the beginning of the sub but I do not dispose of it.  Should I dispose it at the end of the sub?  If I dispose it will it be able to be declared again when the timer elapses again?  Also, since the timer elapses every 2 seconds and its possible for the processes to overlap, what happens if the data reader is declared by one process but a process which started later disposes of that data reader before the original process does.  Will the original process still be able to access that data reader?

I hope I explained well enough.  If not let me know a.  Thanks!!

Start Free Trial
[+][-]04.03.2008 at 06:29PM PDT, ID: 21278438

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 06:41PM PDT, ID: 21278491

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 06:43PM PDT, ID: 21278500

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 08:28PM PDT, ID: 21278866

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 09:14PM PDT, ID: 21279042

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 10:02PM PDT, ID: 21279174

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 11:14PM PDT, ID: 21279382

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Programming for ASP.NET
Tags: vb.net
Sign Up Now!
Solution Provided By: m_kristofer
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628