Re: A question about life cycle of an object.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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: 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)
  • Re: How to make PKCS#7 signature using CryptoAPI?
    ... "Mitch Gallant" wrote: ... Those MSDN samples hash a string PLUS the null byte (so that it ... functions (including CryptSignMessage). ...
    (microsoft.public.platformsdk.security)
  • Re: Base36
    ... static string tokens = ... But - I don't think you want all those silly characters in the product key. ... I should be able to recalc the hash at the client ... > conversion to long so I can pass each long to the BaseXX converter to get ...
    (microsoft.public.dotnet.languages.csharp)