Search This Blog

Friday, April 25, 2008

CONDG Presentation

I'm very grateful to all those who attended the presentation Scott and I gave last night. I will be doing a screencast next week of the demo that I was unable to get to due to technical difficulties. I guess I need to clear up something that I said last night because I was asked about this more than anything else:

Johnny Cash was an immensely influential American singer and song writer and is probably the most recognized country musician of all time. His 'calling card' and what most people associate with him was the dark clothing he wore, usually all black, hence the crack on myself before I gave my presentation

Tuesday, April 15, 2008

.NET Garbage Collection PopQuiz Quick Answers

all credit to Tess for this.

the original quiz can be found here

Tess's answers and further explanation can be found here

1. How many GC threads do we have in a .NET process running the Server version of the GC on a dual-core machine?

A: server version = one thread per logical processor = two threads (four if hyper threaded)

2. What GC mode is used in the web development server (cassini) on a quad proc machine? Why? (you can choose from server, workstation or concurrent-workstation)

A: cassini = windows forms app = user interaction = use concurrent-workstation

3. How many finalizer threads do we have in a .NET process running the Server version of the GC on a quad proc machine?

A: Tess states that the answer is one per process. further investigation only lead to more confusion - server version of GC on a quad proc machine means four GC threads (eight if hyper threaded). i believe the answer is either one or four/eight. i'll keep reading and update this when i find an explanation that makes sense to me

UPDATE: the gentleman walker looked into this and found that, at a given time, there is one per .NET process with a maximum equal to the sum of the number of worker process allocated to each application pool. the process will only show up in taskman if the associated app pool/web site is in use


4. When is an object garbage collected?

A: when the object is no longer referenced and a GC occurs for the generation your object is in

5. What causes an object to move from Generation 0 to Generation 1 or to Generation 2?

A: the object is still referenced when a GC occurs for the generation the object is in

6. If you look at the GC sizes for Generation 0, 1 and 2 in perfmon, why is most of the memory in the process in Gen 2?

A: gen 0 and gen 1 have small sizes (though these sizes are not fixed); gen 2 does not. since GC occurs when gen 0 and gen 1 are nearly 'full', referenced objects will eventually end up in gen 2 where they will remain for the remainder of their life (i.e. until they are no longer referenced and eventually cleaned up)

7. How many heaps will you have at startup on a 4 proc machine running the server GC? How many would you have if the same machine was running the workstation GC? Will the memory used for these show up in private bytes or virtual bytes in perfmon or both?

A: one small object heap and one large object heap per logical processor for server GC; one small object heap and one large object heap in workstation GC. as far as the memory part of the question, this is how i understand it - virtual bytes corresponds to memory reserved by a process, whereas private bytes is the memory actually being used by the process. if all goes smoothly, the graphs for these will follow each other which means the process is allocating memory correctly. at startup, virtual bytes may be a lot larger than private because the reserved memory hasn't been used it, but private bytes should eventually catch up to an extent and both should smooth out in perfmon

8. (Leading question:)) Is the fact that you have mscorwks.dll loaded in the process in 2.0 an indication of that you are running the workstation version of the GC?

A: no; in 2.0, both the server and workstation versions of the GC reside in mscorwks.dll

9. Can you manually switch GC modes for a process? If so, how and under what circumstances?

A: the answer is "yes, but...". i'll leave Tess to explain the restrictions:

a) you can not run the server version on a single proc box, it will default to workstation

b) you can not run concurrent while also running server

c) if the runtime is hosted, the hosts GC mode will override the configuration


10. Name at least 2 ways to make objects survive GC collections unnecessarily.

A: create an unnecessary finalize method. create a objects within a method and then have the method perform some action for a long time, preferably one that causes memory pressure which will trigger a GC and the referenced objects will not be collected

11. Can a .NET application have a *real* memory leak? In the C++ sense where we allocate a chunk of memory and throw away the handle/pointer to it?

A: not in the C++ sense, but leaking memory is quite possible. see Tess lab 6 (which was also covered in my presentation)

12. Why is it important to close database connections and dispose of objects? Doesn't the GC take care of that for me?

A: disposing the objects releases their resources and makes them available for GC immediately (note: calling dispose on an object does not trigger a GC)