Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6946633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:35:24+00:00 2026-05-27T13:35:24+00:00

I programed the windows service to do a routine work. I InstallUtil it to

  • 0

I programed the windows service to do a routine work.

I InstallUtil it to windows service and it’will wake up and do something and then thread.sleep(5min)

The code is simple, but I’ve noticed a potential memory leak. I traced it using DOS tasklist and drew a chart:
enter image description here

Can I say that it’s pretty clear there was memory leak, although so little.

My code is like below, Please help me to find the potential leak. Thanks.

    public partial class AutoReport : ServiceBase
    {
        int Time = Convert.ToInt32(AppSettings["Time"].ToString());
        private Utilities.RequestHelper requestHelper = new RequestHelper();

        public AutoReport()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Thread thread = new Thread(new ParameterizedThreadStart(DoWork));
            thread.Start();
        }

        protected override void OnStop()
        {
        }

        public void DoWork(object data)
        {
            while (true)
            {
                string jsonOutStr = requestHelper.PostDataToUrl("{\"KeyString\":\"somestring\"}", "http://myurl.ashx");
                Thread.Sleep(Time);
            }
        }
    }

Edit: After using WinDbg @Russell suggested. What should I do to these classes?

MT  Count   TotalSize   ClassName
79330b24    1529    123096  System.String
793042f4    471 41952   System.Object[]
79332b54    337 8088    System.Collections.ArrayList
79333594    211 70600   System.Byte[]
79331ca4    199 3980    System.RuntimeType
7a5e9ea4    159 2544    System.Collections.Specialized.NameObjectCollectionBase+NameObjectEntry
79333274    143 30888   System.Collections.Hashtable+bucket[]
79333178    142 7952    System.Collections.Hashtable
79331754    121 57208   System.Char[]
7a5d8120    100 4000    System.Net.LazyAsyncResult
00d522e4    95  5320    System.Configuration.FactoryRecord
00d54d60    76  3952    System.Configuration.ConfigurationProperty
7a5df92c    74  2664    System.Net.CoreResponseData
7a5d8060    74  5032    System.Net.WebHeaderCollection
79332d70    73  876 System.Int32
79330c60    73  1460    System.Text.StringBuilder
79332e4c    72  2016    System.Collections.ArrayList+ArrayListEnumeratorSimple
7.93E+09    69  1380    Microsoft.Win32.SafeHandles.SafeTokenHandle
7a5e0d0c    53  1060    System.Net.HeaderInfo
7a5e4444    53  2120    System.Net.TimerThread+TimerNode
79330740    52  624 System.Object
7a5df1d0    50  2000    System.Net.AuthenticationState
7a5e031c    50  5800    System.Net.ConnectStream
7aa46f78    49  588 System.Net.ConnectStreamContext
793180f4    48  960 System.IntPtr[]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:35:25+00:00Added an answer on May 27, 2026 at 1:35 pm

    This is how I’d go about finding the memory leak:

    1) Download WinDbg if you don’t already have it. It’s a really powerful (although difficult to use as it’s complicated) debugger.

    2) Run WinDbg and attach it to your process by pressing F6 and selecting your exe.

    3) When it has attached type these commands: (followed by enter)

    //this will load the managed extensions

    .loadby sos clr

    //this will dump the details of all your objects on the heap

    !dumpheap -stat

    //this will start the service again

    g

    Now wait a few minutes and type Ctrl+Break to break back into the service. Run the !Dumpheap -stat command again to find out what is on the heap now. If you have a memory leak (in managed code) then you will see one or more of your classes keep getting added to the heap over time. You now know what is being kept in memory so you know where to look for the problem in your code. You can work out what is holding references to the objects being leaked from within WinDbg if you like but it’s a complicated process. If you decide to use WinDbg then you probably want to start by reading Tess’s blog and doing the labs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an executable that is started by a windows service, this program will
I have a very simple VB.net Windows Service written using VS.net 2008. The program
Possible Duplicates: windows service vs scheduled task Windows Service Vs Simple Program I'm trying
I have a Windows Service written in Delphi which runs a number of programs.
I have an ASP.NET web service that I can access via a windows program
Well behaved windows programs need to allow users to save their work when they
Below is the usual Program.cs content for a windows service program: static class Program
I would like to wrap a java program into a windows service with C#
My project contains WinForms, WPF, and Windows Service programs running on users' office desktop
I've created an application in C# which I run as a Windows Service. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.