[Gc] Re: Want to find reason of heap size keep growth

Bruce Hoult bruce at hoult.org
Fri Jul 9 01:13:01 PDT 2010


On Fri, Jul 9, 2010 at 7:42 PM, biosli <biosli at hotmail.com> wrote:
> Bruce Hoult <bruce at ...> writes:
>> Repeated allocation and freeing of such a large object is very likely
>> to cause fragmentation and heap growth because once that space is in
>> the heap and has been freed it is likely to start being used for
>> smaller objects. Next time you need a large object there is no
>> contiguous space and more has to be allocated.
>
> I know the reason now, thanks. But is there some way let GC compress data,
> that make small object together, then it will left more space for large block?

No, the gc does not know where the pointers to an object are, so it
can not update pointers to objects, so it can't move objects. And,
because it is conservative, things that look like pointers to an
object might not be.


>> Use your own free list for large objects, possibly rounding up to a
>> few standard sizes if the natural size varies.
>
> It's mean that I should ues OS malloc for all large block data and free them
> by my self?

Using the OS malloc and free repeatedly on large objects is likely to
cause the same kinds of problems.

The meaning of "Use your own free list" is that you never actually
free the objects, you add them to a list when they are no longer
needed. When you want to allocate a large object you check to see if
there is already a suitable one on the list.

You can manage putting such large objects on to your custom free list
manually, or you can use a finalizer to do it.


More information about the Gc mailing list