From: Florian Gilcher Date: 2009-11-11T00:26:24+09:00 Subject: Re: Good or best way to allocate a large array On Nov 10, 2009, at 10:39 AM, Robert Klemme wrote: > >> As you correctly stated, the first example allocs (300_000*20 + 1) >> objects. The interesting point in this is that it triggers the >> GC more than once, although there is nothing to collect. > > Well, but this is expected: the second example has more need for > memory (every time a new BigNum must be created), and if memory is > needed it is reasonable to first start GC before asking the OS for > more memory. GC cannot know that it will not find anything > collectible. > > Kind regards > > robert It was not meant as a complaint, more as an explanation why the behavior in my first mail happens (~~40% performance gain by switching off the GC before allocating the array). It is just a sample where the heuristic applied by the GC somewhat fails. The GC behavior is reasonable, but not efficient in that case. In most cases, this one second does not really matter, so I would recommend against tampering with it. Thats why I wrote that you should handle this with care. It is, in the end, a nice example illustrating how the GC behaves and that's what I used it for. Regards, Florian