"Barry Kelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> rossum <(E-Mail Removed)> wrote:
>
>> On Sun, 23 Jul 2006 02:40:02 GMT, "Jim" <(E-Mail Removed)> wrote:
>>
>> >Each time the user starts a new design, the array should be initialized.
>> >It is not known beforehand what its size will be, although a typical
>> >size is on the order of a million objects. I need some
>> >way of freeing the memory.
>>
>> Set all references to the array to null and call System.GC.Collect()
>> which will force the garbage collector to run. This may take some
>> time if it has a lot of work to do so your users might notice a pause.
>
> This is using a sledgehammer to pound in a nail, IMHO. The cost of using
> large arrays without pooling is that gen 2 collections occur
> occasionally. Calling GC.Collect() will force a gen 2 collection every
> time you call it.
>
> -- Barry
>
> --
> http://barrkel.blogspot.com/
Barry and rossum:
Thanks to *both of you* for good suggestions. I may be forced to go the
memory pool route, but it does violate a ground rule here: I would
rather the user's design dictate the resources consumed (there are many
other objects besides the array I described earlier), rather than
having the resources dictate one facet of the largest design.
In other words, if I use a technique that cleans up between
iterations, then the user's iteration can trade off maximum
array size for maximum print buffer size which is only
loosely coupled to the array size. The print buffer is
built as the design iteration progresses; each step goes
practically unnoticed by the user. But building a print buffer
all at once... well, it would give him time to go fetch
a fresh cup of coffee.
It does so happen I globbed onto the GarbageCollector
Collect ( ) method after posting my earlier message here,
and found it acceptable up to about 500 k objects.
After that, yes, there is a bit of a balky delay although
shorter than the program's startup initialization which
reads a database. A finicky user may do a dozen
design iterations, and more, depending on how much
of a perfectionist s/he is.
I don't know which way I'm going to proceed just yet.
I'm going to fetch a cup of coffee and run some more
experiments. I'm tempted to offer both features
to the user and call them "Optimize for speed" or
"Optimize for memory usage". This has to be
traded off with how much effort we want to
spend explaining the ramifications to the
user who only knows what he sees on the
screen and doesn't care about the code
behind it all.