Click here to Skip to main content
15,887,477 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralAdding to the TextBox context menu Pin
MitchellBaldwin24-Feb-05 6:35
MitchellBaldwin24-Feb-05 6:35 
GeneralRe: Adding to the TextBox context menu Pin
pankajupadhyay2930-Nov-09 20:17
professionalpankajupadhyay2930-Nov-09 20:17 
GeneralProcess memory not right Pin
Turok_4_2_024-Feb-05 4:12
Turok_4_2_024-Feb-05 4:12 
GeneralRe: Process memory not right Pin
S. Senthil Kumar24-Feb-05 8:47
S. Senthil Kumar24-Feb-05 8:47 
GeneralRe: Process memory not right Pin
Turok_4_2_024-Feb-05 14:17
Turok_4_2_024-Feb-05 14:17 
GeneralChanging child control property of a form from another form Pin
erossetto24-Feb-05 2:50
erossetto24-Feb-05 2:50 
Generalmicrosoft visio Pin
lalitmohankohli24-Feb-05 0:17
lalitmohankohli24-Feb-05 0:17 
GeneralMemory oddness Pin
Ray Cassick23-Feb-05 16:58
Ray Cassick23-Feb-05 16:58 
I have been beating myself up over trying to locate what I thought was a memory leak in MY code but based upon what I have seen I can't be sure that it IS my fault or something strange with DOTNET. Someone here please feel free to enlighten me on this one.

The code to reproduce is very simple. Done in VB.NET (please no language based flames here - I am already working up a C# version just to be safe Smile | :) ) , One form with a button on it called cmdStart. Here is the code behind the form:

Public Class Form1
    Inherits System.Windows.Forms.Form


     Dim t1 As System.Threading.Thread
     Dim t2 As System.Threading.Thread
     Dim t3 As System.Threading.Thread
     Dim t4 As System.Threading.Thread
     Dim t5 As System.Threading.Thread


#Region " Windows Form Designer generated code " 'This has been clipped out for brevity here


 Private Sub ThreadWorker()


  Do
   Debug.WriteLine("Thread Enter. [" & System.Threading.Thread.CurrentThread.Name & "]")
   System.Threading.Thread.CurrentThread.Sleep(1000)
   Debug.WriteLine("Thread exit [" & System.Threading.Thread.CurrentThread.Name & "]")


  Loop


 End Sub


 Private Sub cmdStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdStart.Click


  t1 = New System.Threading.Thread(AddressOf ThreadWorker)
  t1.Name = "T1"
  t1.IsBackground = True
  t1.Start()


  t2 = New System.Threading.Thread(AddressOf ThreadWorker)
  t2.Name = "T2"
  t2.IsBackground = True
  t2.Start()


  t3 = New System.Threading.Thread(AddressOf ThreadWorker)
  t3.Name = "T3"
  t3.IsBackground = True
  t3.Start()


  t4 = New System.Threading.Thread(AddressOf ThreadWorker)
  t4.Name = "T4"
  t4.IsBackground = True
  t4.Start()


  t5 = New System.Threading.Thread(AddressOf ThreadWorker)
  t5.Name = "T5"
  t5.IsBackground = True
  t5.Start()


 End Sub


End Class


Now, you ask what the problem is here? It appears to me that there is a memory leak afoot.At least according to perfmon.

When I monitor the privateBytes for the test app running these threads and sample every 60 seconds I get a very definite memory increase shown.

My question here is WHY?!? My thread is not creating any resources unless you count anything allocated internally by the framework to perform the debug prints. I am testing this running debug build of the app and to be honest I have not tested a release build yet so I cannot comment on what those results are.

Now, keep in mind that my app is MUCH more complicated than this, but I am seeing the same results here as I am in my app. I thought originally that I was seeing some memory issues because I was creating a clone of a few hashtables inside my threads and I thought perhaps that was causing some GC issues but now I am not so sure. In fact when I ran my app with all the internals of the threads commented out except for the debugs and sleeps as I have here I still see the apparent memory creep.

Can ANYONE explain to me what I am seeing here?

Am I going nuts?

I have to admit that I am by no means a threading master yet but this seems pretty basic to me.

The even stranger part is that, while I am typing this in I happened to look at perfmon and see that it appears to have eventually leveled off after about 14 minutes. The memory appears to have gone from 6654720 to approx 7772000. That is a growth of 117280 bytes. Not allot but I still don't understand why the memory is growing. Can this all be explained away by GC? Seems a bit odd since I am not allocating anything in my app on a cyclic basis.


Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.


GeneralRe: Memory oddness Pin
Mike Dimmick24-Feb-05 5:12
Mike Dimmick24-Feb-05 5:12 
GeneralRe: Memory oddness Pin
Ray Cassick24-Feb-05 6:29
Ray Cassick24-Feb-05 6:29 
GeneralRe: Memory oddness Pin
Turok_4_2_024-Feb-05 14:22
Turok_4_2_024-Feb-05 14:22 
GeneralRe: Memory oddness Pin
Andy Brummer24-Feb-05 8:09
sitebuilderAndy Brummer24-Feb-05 8:09 
GeneralChange path of "obj" directory in .NET Pin
Mohammed Saleem23-Feb-05 0:02
Mohammed Saleem23-Feb-05 0:02 
GeneralProblems with process spawning Pin
usman.ghani22-Feb-05 8:11
usman.ghani22-Feb-05 8:11 
GeneralRe: Problems with process spawning Pin
S. Senthil Kumar22-Feb-05 18:09
S. Senthil Kumar22-Feb-05 18:09 
GeneralRe: Problems with process spawning Pin
usman.ghani26-Feb-05 3:15
usman.ghani26-Feb-05 3:15 
Generalcreate copy of a hashtable... Pin
Ray Cassick21-Feb-05 19:09
Ray Cassick21-Feb-05 19:09 
GeneralRe: create copy of a hashtable... Pin
S. Senthil Kumar22-Feb-05 18:07
S. Senthil Kumar22-Feb-05 18:07 
GeneralLoading Assembly from a Web Service Pin
Vadim Tabakman21-Feb-05 18:29
Vadim Tabakman21-Feb-05 18:29 
Generalwindows application write to console Pin
krealiza21-Feb-05 16:42
krealiza21-Feb-05 16:42 
GeneralRe: windows application write to console Pin
Rei Miyasaka22-Feb-05 17:35
Rei Miyasaka22-Feb-05 17:35 
GeneralRe: windows application write to console Pin
krealiza22-Feb-05 17:57
krealiza22-Feb-05 17:57 
GeneralRe: windows application write to console Pin
Rei Miyasaka22-Feb-05 18:00
Rei Miyasaka22-Feb-05 18:00 
GeneralRe: windows application write to console Pin
krealiza22-Feb-05 18:13
krealiza22-Feb-05 18:13 
GeneralRe: windows application write to console Pin
Rei Miyasaka22-Feb-05 18:40
Rei Miyasaka22-Feb-05 18:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.