Re: A question about life cycle of an object.

Tech-Archive recommends: Speed Up your PC by fixing your registry



BTW, I missed some information in my post.
When I tested with a hashtable object, I called the Clear() method of
the hashtable instance at the end of Test1() method.
After the Clear() call, references to those string object should be
counted down to 0 I think, and all those string objects should stay in
gen0 and should be collected for a while. But when I check the memory
used by the process after running for 1 hour, it still remains the
same.


On Apr 25, 3:45 am, Barry Kelly <barry.j.ke...@xxxxxxxxx> wrote:
Xiuming wrote:
Before starting this discussion, I have already searched for
informations about how GC works, I create a instance of StringBuilder
class is just for an example.
In fact, I create a instance of Hashtable class and add 10000000
string objects, the same thing happens.

Why?

A hashtable with live references to 10,000,000 strings is just as much a
large object graph as a string builder. The situation is no different.
The GC can't collect any of it while the hashtable is rooted. Since lots
and lots of string allocations were needed to add the objects to the
table, a few GCs probably happened in the meantime. But because nothing
could get collected (because everything was kept alive in the hash
table), the memory for the strings and the hash table would have moved
from gen0 to gen2 (I presume you know what these are if you've read
about CLR GC).

Thus, once the hash table is no longer rooted (e.g. nulled out, or the
variable goes out of scope), the GC won't collect it immediately. It'll
have to wait until a gen2 collection for it to get freed up. That won't
happen until both gen0 and gen1 collections occur, which may require
many intermediate allocations, depending on the sizes of gen0 and gen1
(which are based on historical collection rates).

-- Barry

--http://barrkel.blogspot.com/

.



Relevant Pages

  • Re: A question about life cycle of an object.
    ... string objects, the same thing happens. ... the memory for the strings and the hash table would have moved ... happen until both gen0 and gen1 collections occur, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: A question about life cycle of an object.
    ... string objects, the same thing happens. ... the memory for the strings and the hash table would have moved ... happen until both gen0 and gen1 collections occur, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: How to write a diff in VB6 for comparing two xml files?
    ... No, the best you could do is to read both into string and use StrCompbut it's inefficient and, but using the hash ... Private Declare Function CryptAcquireContext Lib "AdvAPI32.dll" Alias _ ... Dim HashAAs Byte, HashLenA As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: something like switch in c
    ... >> straightforward string comparisions. ... > inner table size and/or add symbols to expand the hash. ... It all depends on the empirical pattern of the actual keys. ... The value of the random number generator is UNCHANGED on ...
    (comp.programming)
  • Re: How to make PKCS#7 signature using CryptoAPI?
    ... Those MSDN samples hash a string PLUS the null byte (so that it ... I tried your sample and had no problem verifying with openssl (after I added ... functions (including CryptSignMessage). ...
    (microsoft.public.platformsdk.security)