Question Memory Leak, what could be the cause?

Gunzedreng

Member
Joined
Feb 20, 2012
Messages
9
Location
Denmark
Programming Experience
1-3
Hi all,

I have a bit of an issue with one of my Applications, it seems to crash after a certain periode of time and I can't really find out why, so I made a Logfile entry with Memory information every minute to see where the increase is.
Cannot really provide with any code since it is very large and could be anything. The cause would propably be related to either the TcpListener Class I've created, Sql Server Communication. But here is some of the data acquired from logfiles:

***** Application Started
***** 13 Februar 2012
14:14 | PagedMemSize64: 34280K | PrivateMemSize64: 34280K | PagedSystemMemSize64: 323,28125K | PeakPageMemSize64: 36172K | PeakVirtualMemSize64: 236676K | PeakWorkingSetMemSize64: 44300K | GC TotalMemory: 1248980 bytes
14:15 | PagedMemSize64: 34616K | PrivateMemSize64: 34616K | PagedSystemMemSize64: 323,1796875K | PeakPageMemSize64: 36660K | PeakVirtualMemSize64: 236804K | PeakWorkingSetMemSize64: 44676K | GC TotalMemory: 1298556 bytes
14:16 | PagedMemSize64: 36700K | PrivateMemSize64: 36700K | PagedSystemMemSize64: 323,9296875K | PeakPageMemSize64: 38776K | PeakVirtualMemSize64: 237764K | PeakWorkingSetMemSize64: 44876K | GC TotalMemory: 1298036 bytes
23:57 | PagedMemSize64: 42012K | PrivateMemSize64: 42012K | PagedSystemMemSize64: 332,2890625K | PeakPageMemSize64: 44140K | PeakVirtualMemSize64: 243160K | PeakWorkingSetMemSize64: 49656K | GC TotalMemory: 1389336 bytes
23:58 | PagedMemSize64: 42012K | PrivateMemSize64: 42012K | PagedSystemMemSize64: 332,2890625K | PeakPageMemSize64: 44140K | PeakVirtualMemSize64: 243160K | PeakWorkingSetMemSize64: 49656K | GC TotalMemory: 1384112 bytes
23:59 | PagedMemSize64: 42012K | PrivateMemSize64: 42012K | PagedSystemMemSize64: 332,2890625K | PeakPageMemSize64: 44140K | PeakVirtualMemSize64: 243160K | PeakWorkingSetMemSize64: 49656K | GC TotalMemory: 1389312 bytes
***** 14 Februar 2012
14:14 | PagedMemSize64: 46348K | PrivateMemSize64: 46348K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 48728K | PeakVirtualMemSize64: 245212K | PeakWorkingSetMemSize64: 53036K | GC TotalMemory: 1339756 bytes
14:15 | PagedMemSize64: 46348K | PrivateMemSize64: 46348K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 48728K | PeakVirtualMemSize64: 245212K | PeakWorkingSetMemSize64: 53036K | GC TotalMemory: 1334712 bytes
14:16 | PagedMemSize64: 46348K | PrivateMemSize64: 46348K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 48728K | PeakVirtualMemSize64: 245212K | PeakWorkingSetMemSize64: 53036K | GC TotalMemory: 1334964 bytes
23:57 | PagedMemSize64: 48352K | PrivateMemSize64: 48352K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 50428K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 55064K | GC TotalMemory: 1335932 bytes
23:58 | PagedMemSize64: 48352K | PrivateMemSize64: 48352K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 50428K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 55064K | GC TotalMemory: 1335608 bytes
23:59 | PagedMemSize64: 48356K | PrivateMemSize64: 48356K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 50428K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 55064K | GC TotalMemory: 1332564 bytes
***** 15 Februar 2012
14:14 | PagedMemSize64: 51544K | PrivateMemSize64: 51544K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 54044K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 58544K | GC TotalMemory: 1433272 bytes
14:15 | PagedMemSize64: 51544K | PrivateMemSize64: 51544K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 54044K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 58544K | GC TotalMemory: 1433464 bytes
14:16 | PagedMemSize64: 51540K | PrivateMemSize64: 51540K | PagedSystemMemSize64: 332,609375K | PeakPageMemSize64: 54044K | PeakVirtualMemSize64: 253376K | PeakWorkingSetMemSize64: 58544K | GC TotalMemory: 1433192 bytes
23:57 | PagedMemSize64: 53544K | PrivateMemSize64: 53544K | PagedSystemMemSize64: 332,65625K | PeakPageMemSize64: 55624K | PeakVirtualMemSize64: 253408K | PeakWorkingSetMemSize64: 60584K | GC TotalMemory: 1433760 bytes
23:58 | PagedMemSize64: 53544K | PrivateMemSize64: 53544K | PagedSystemMemSize64: 332,65625K | PeakPageMemSize64: 55624K | PeakVirtualMemSize64: 253408K | PeakWorkingSetMemSize64: 60584K | GC TotalMemory: 1438708 bytes
23:59 | PagedMemSize64: 53548K | PrivateMemSize64: 53548K | PagedSystemMemSize64: 332,65625K | PeakPageMemSize64: 55624K | PeakVirtualMemSize64: 253408K | PeakWorkingSetMemSize64: 60584K | GC TotalMemory: 1433748 bytes
***** 16 Februar 2012
14:14 | PagedMemSize64: 57604K | PrivateMemSize64: 57604K | PagedSystemMemSize64: 333,015625K | PeakPageMemSize64: 59684K | PeakVirtualMemSize64: 269600K | PeakWorkingSetMemSize64: 63652K | GC TotalMemory: 1432848 bytes
14:15 | PagedMemSize64: 57604K | PrivateMemSize64: 57604K | PagedSystemMemSize64: 333,015625K | PeakPageMemSize64: 59684K | PeakVirtualMemSize64: 269600K | PeakWorkingSetMemSize64: 63652K | GC TotalMemory: 1432828 bytes
14:16 | PagedMemSize64: 57604K | PrivateMemSize64: 57604K | PagedSystemMemSize64: 333,015625K | PeakPageMemSize64: 59684K | PeakVirtualMemSize64: 269600K | PeakWorkingSetMemSize64: 63652K | GC TotalMemory: 1432828 bytes
23:57 | PagedMemSize64: 59688K | PrivateMemSize64: 59688K | PagedSystemMemSize64: 332,984375K | PeakPageMemSize64: 61768K | PeakVirtualMemSize64: 270608K | PeakWorkingSetMemSize64: 65760K | GC TotalMemory: 1437644 bytes
23:58 | PagedMemSize64: 59688K | PrivateMemSize64: 59688K | PagedSystemMemSize64: 332,984375K | PeakPageMemSize64: 61768K | PeakVirtualMemSize64: 270608K | PeakWorkingSetMemSize64: 65760K | GC TotalMemory: 1432420 bytes
23:59 | PagedMemSize64: 59712K | PrivateMemSize64: 59712K | PagedSystemMemSize64: 332,984375K | PeakPageMemSize64: 61788K | PeakVirtualMemSize64: 270608K | PeakWorkingSetMemSize64: 65768K | GC TotalMemory: 1434264 bytes
***** 17 Februar 2012
14:14 | PagedMemSize64: 63084K | PrivateMemSize64: 63084K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 65412K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 70044K | GC TotalMemory: 1485896 bytes
14:15 | PagedMemSize64: 63084K | PrivateMemSize64: 63084K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 65412K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 70052K | GC TotalMemory: 1488648 bytes
14:16 | PagedMemSize64: 63084K | PrivateMemSize64: 63084K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 65412K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 70056K | GC TotalMemory: 1490908 bytes
23:57 | PagedMemSize64: 65072K | PrivateMemSize64: 65072K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 67260K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 72104K | GC TotalMemory: 1536484 bytes
23:58 | PagedMemSize64: 65072K | PrivateMemSize64: 65072K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 67260K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 72104K | GC TotalMemory: 1531260 bytes
23:59 | PagedMemSize64: 65072K | PrivateMemSize64: 65072K | PagedSystemMemSize64: 339,3515625K | PeakPageMemSize64: 67260K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 72104K | GC TotalMemory: 1531260 bytes
***** 18 Februar 2012
14:14 | PagedMemSize64: 67832K | PrivateMemSize64: 67832K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 69924K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 74920K | GC TotalMemory: 1505364 bytes
14:15 | PagedMemSize64: 67832K | PrivateMemSize64: 67832K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 69924K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 74920K | GC TotalMemory: 1504544 bytes
14:16 | PagedMemSize64: 67832K | PrivateMemSize64: 67832K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 69924K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 74920K | GC TotalMemory: 1501992 bytes
23:56 | PagedMemSize64: 70080K | PrivateMemSize64: 70080K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 72160K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 77128K | GC TotalMemory: 1551068 bytes
23:57 | PagedMemSize64: 70080K | PrivateMemSize64: 70080K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 72160K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 77128K | GC TotalMemory: 1551068 bytes
23:58 | PagedMemSize64: 70080K | PrivateMemSize64: 70080K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 72160K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 77128K | GC TotalMemory: 1550504 bytes
***** 19 Februar 2012
06:26 | PagedMemSize64: 71356K | PrivateMemSize64: 71356K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1519112 bytes
06:27 | PagedMemSize64: 71356K | PrivateMemSize64: 71356K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1522548 bytes
06:28 | PagedMemSize64: 71356K | PrivateMemSize64: 71356K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1516684 bytes
06:30 | PagedMemSize64: 71356K | PrivateMemSize64: 71356K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1514772 bytes
06:31 | PagedMemSize64: 72384K | PrivateMemSize64: 72384K | PagedSystemMemSize64: 339,265625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1536276 bytes
06:32 | PagedMemSize64: 71360K | PrivateMemSize64: 71360K | PagedSystemMemSize64: 338,890625K | PeakPageMemSize64: 74560K | PeakVirtualMemSize64: 275160K | PeakWorkingSetMemSize64: 78460K | GC TotalMemory: 1522204 bytes
***** CRASH !!! Window Hung


***** Calculation Increase from Application Start to Crash! Time Period (13Feb-14:14 to 19Feb-06:32 = 5Days 16Hours 18Minutes)
******************************************************************************************************************************
CALC: | PagedMemSize64: +37080K PrivateMemSize64: +37080K PagedSystemMemSize64: +15,609375K PeakPageMemSize64: +38388K PeakVirtualMemSize64: +38484K | PeakWorkingSetMemSize64: +34160K GC TotalMemory: +273224 bytes

and there is clearly an increase in memory but what could be the issue, and what would be the pursuit of this issue, or is there a way to DUMP the memory from the Application:

With Kind Regards
Gunnar Stefansson
 

brendon

New member
Joined
Feb 25, 2012
Messages
3
Programming Experience
5-10
Gunnar,

Have you perhaps considered looking in to 'Garbage Collection'? Forcing the collection of garbage at a set interval, say every 1 minute for example, would lower the amount of memory your application is using.

Just to test it out, you could throw a simple "GC.Collect()" in a new Timer's 'Tick' event with an interval of '60000', and then compare your memory logs.

Here are a couple of reference links on Garbage Collection:
-> GC Class (System)
-> Garbage Collection in .NET - A deeper look for the beginners - CodeProject®

Also, are you ensuring that you are disposing your object instances? Consider the 'Using' statement rather than an excessive amount of 'Dim ___ As ___', as the 'Using' statement will automatically invoke the 'Dispose' method of an object (if it implements IDisposable) within the 'Using ... End Using' code block once it has completed.

You can see more information on the 'Using' statement here: Using Statement and Dispose Method in C# and VB.NET - CodeProject®

Hope this helps.

Good luck,
Brendon
 

Gunzedreng

Member
Joined
Feb 20, 2012
Messages
9
Location
Denmark
Programming Experience
1-3
Hi Brendon,

Thank you very much for your reply, I will try to use the Garbage collection first and see what happens...

If it does not have any affect, the using will propably do the trick, but will consume a lot of time :)

Anyway, I will report back after the GC.Collect has been added.

Thanks
Gunze
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,744
Location
Sydney, Australia
Programming Experience
10+
Calling GC.Collect explicitly is generally not good practice. You might try it to see if it makes a difference but that would most likely just be a diagnostic tool and not something that you'd leave in a Release build.

Also, disposing doesn't really affect memory usage directly because disposing doesn't release memory. Memory can be released faster if you explicitly dispose because the system won't have to do it later but not disposing won't prevent memory being reclaimed. A disposed object still occupies memory so disposing won't cause memory to be reclaimed either.

What will cause memory usage to increase is not removing references. If you create an object and assign it to a variable or array element, as long as that reference to the object remains, it cannot be cleaned up by the garbage collector. That's true whether it is disposed or not. In order to remove a reference, either a variable must fall out of scope or it must be explicitly set to Nothing.
 
Top Bottom