John,
don't tease your brain - tease CLR Profiler and your app.
Profiler shows every single allocation. Unfortunately I cannot check the
code and guarantee if this is really so, however my practice is that if
something is allocated - even 1byte string - it could be found in CLR
Profiler data. If profiler doesn't crash...
Also, it seems profiler influences heavily GC behavior - freed memory is not
collected as quickly as in non-profiled application.
About your Q: it will be 5(6) different allocations until cleaned out by GC.
Depending on how long is delay between myVar assignment and ProcessString -
it might survive several GC cycles - all gens. tmpTest instance and 4 other
strings will be freed when GC kicks in - however when this will happen
nobody can say - use your app and profiler.
Another point: it doesn't make much point to tease your brain over such
examples. In real applications behavior is sometimes very different from
what you see in simple code snippets. Take good note of info in
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp
HTH
Alex
[quoted text, click to view] "John Linn" <JohnLinn@discussions.microsoft.com> wrote in message
news:141F8FCA-B70C-4AA4-8352-53A534D8152B@microsoft.com...
> Let's say I have this object:
>
> public class void MyTest() {
> public string str1 = [1k worth of text];
> public string str2 = [1k worth of text];
> public string str3 = [1k worth of text];
> public string str4 = [1k worth of text];
> public string str5 = [1k worth of text];
> }
>
> MyTest tmpTest = new MyTest();
>
> .NET requires ~5k of continuous free memory to allocate this object,
correct? The object instance and the string instances are stored together?
>
> Side question: In CLRProfiler, will this object show up as one 5kb object,
or will it show as 6 distinct objects?
>
> Now, let's say I do this:
> string myVar = tmpTest.str3;
> tmpTest = null;
> <---------- lets say under load, a GC happened here.
> ProcessString(myVar);
>
> Does the tmpTest instance and the 4 other strings get cleaned-up? Does the
re-assigned string get promoted to gen 1? And if another GC happened before
myVar got marked for removable, would it slide into Gen2?
[quoted text, click to view] >
> Still trying to get my brain around this stuff.. =)
>
> JL