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

.NET (Core and Framework)

 
QuestionChanging the windows desktop background color programmatically Pin
BarV23-Aug-06 7:29
BarV23-Aug-06 7:29 
AnswerRe: Changing the windows desktop background color programmatically Pin
Jun Du23-Aug-06 8:12
Jun Du23-Aug-06 8:12 
GeneralRe: Changing the windows desktop background color programmatically Pin
BarV30-Aug-06 19:28
BarV30-Aug-06 19:28 
Question[Message Deleted] Pin
R_L_H23-Aug-06 4:02
R_L_H23-Aug-06 4:02 
AnswerRe: Questions about Framework 2.0 Garbage Collection and Memory Management Pin
Steve Maier23-Aug-06 4:22
professionalSteve Maier23-Aug-06 4:22 
AnswerRe: Questions about Framework 2.0 Garbage Collection and Memory Management Pin
Dan Neely23-Aug-06 4:29
Dan Neely23-Aug-06 4:29 
AnswerRe: Questions about Framework 2.0 Garbage Collection and Memory Management Pin
Dan Neely23-Aug-06 4:31
Dan Neely23-Aug-06 4:31 
AnswerRe: Questions about Framework 2.0 Garbage Collection and Memory Management [modified] Pin
Mike Dimmick23-Aug-06 10:23
Mike Dimmick23-Aug-06 10:23 
The 'Mem Usage' column in Task Manager is actually the current working set size. The working set is the set of physical memory pages which the OS thinks are currently necessary to run the program. Periodically, about once a second, a thread in the OS called the balance set manager wakes up and trims (removes) pages from each working set on the system, to ensure that there are always enough free physical pages of memory to satisfy demand. There is also an upper limit of working set size for each process, which is defaulted to about 1.5MB, but this is really an advisory limit - if there are enough free pages, this number is ignored. You can set your process's limits with the SetProcessWorkingSetSize function, but there's no benefit in doing so.

When the USER subsystem minimizes a window, it automatically asks the operating system to trim the process's working set, since the assumption is that you aren't going to be using it again straight away. You can get the same effect by calling SetProcessWorkingSetSize, passing -1 for both minimum and maximum working set size parameters.

Pages are added to the working set by allocating them, or, after they've been trimmed, by accessing them. If your program has good locality of reference, the working set will normally stay quite low.

To see how much load you're putting on both physical memory and the page file, enable the VM Size column. This is equivalent to the Process: Private Bytes counter in the Performance tool (in Administrative Tools).

The .NET Framework manages all your allocations from a set of virtual memory allocations. The garbage collector generally just moves data around within the existing allocations, until its newest generation becomes full, at which point it will ask the OS for a new block (referred to as a segment). If it does have a completely free segment after performing a collection, it may return it to the OS - this is the only way that the VM Size column will go down.

To keep the size of the GC heap down, ensure that you're getting rid of your objects promptly. If an object implements the IDisposable interface, or otherwise offers a Close or Dispose method, you must call it when you're finished with the object. If you don't, when the GC runs (and the object has a finalizer) it will go onto a queue (called freachable) for the finalizer thread to run the finalizer. The memory will only be released back to the GC heap when the GC runs again to collect the older generation that the object is now in, after its finalizer has run.

Other things to do are to simply allocate fewer objects. .NET applications can often be 'object-happy' - it's so easy to create an object that it is often done without thinking. To see how many objects you're allocating, and where you're allocating them, run CLR Profiler[^] (for 1.1[^]).

For more on how the GC works, see Maoni Stephens' weblog[^] and this presentation[^] (PPT, 401kB) from PDC 2005.

-- modified at 16:25 Wednesday 23rd August, 2006

Stability. What an interesting concept. -- Chris Maunder

AnswerRe: Questions about Framework 2.0 Garbage Collection and Memory Management Pin
Scott Dorman1-Sep-06 15:57
professionalScott Dorman1-Sep-06 15:57 
QuestionWhy reference variables are stored on heap Pin
karan vidyut23-Aug-06 1:57
karan vidyut23-Aug-06 1:57 
AnswerRe: Why reference variables are stored on heap Pin
Jun Du23-Aug-06 4:41
Jun Du23-Aug-06 4:41 
AnswerRe: Why reference variables are stored on heap Pin
Colin Angus Mackay24-Aug-06 2:27
Colin Angus Mackay24-Aug-06 2:27 
AnswerRe: Why reference variables are stored on heap Pin
Guffa24-Aug-06 3:17
Guffa24-Aug-06 3:17 
QuestionSend page by email Pin
sujasmaill22-Aug-06 22:04
sujasmaill22-Aug-06 22:04 
QuestionProblem hosting webpage on server/ domain Pin
sandeep kumar pundhir22-Aug-06 19:57
sandeep kumar pundhir22-Aug-06 19:57 
AnswerRe: Problem hosting webpage on server/ domain Pin
Mike Dimmick23-Aug-06 0:25
Mike Dimmick23-Aug-06 0:25 
QuestionSystem Administration for Windows Pin
Mostafa Siraj22-Aug-06 10:48
Mostafa Siraj22-Aug-06 10:48 
AnswerRe: System Administration for Windows Pin
Jun Du23-Aug-06 4:46
Jun Du23-Aug-06 4:46 
GeneralRe: System Administration for Windows Pin
Mostafa Siraj23-Aug-06 8:13
Mostafa Siraj23-Aug-06 8:13 
Questionhow to make a dbx file Pin
Parshant Verma22-Aug-06 0:18
Parshant Verma22-Aug-06 0:18 
QuestionPassing Data from ASP.NET to Axis Web Service Pin
bryan paling21-Aug-06 19:24
bryan paling21-Aug-06 19:24 
AnswerRe: Passing Data from ASP.NET to Axis Web Service Pin
stevepham4225-Aug-06 0:22
stevepham4225-Aug-06 0:22 
QuestionRunning other Applications (exe) Pin
Md.Imdad21-Aug-06 10:41
Md.Imdad21-Aug-06 10:41 
AnswerRe: Running other Applications (exe) Pin
Jun Du22-Aug-06 12:44
Jun Du22-Aug-06 12:44 
QuestionASP .NET Datagrid SQL SELECT Parameter Problem Pin
Soot21-Aug-06 9:57
Soot21-Aug-06 9:57 

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.