Garbage collector memory leak "feature"?

0ffh spam at frankhirsch.net
Wed Oct 10 09:25:32 PDT 2007


Steven Schveighoffer wrote:
> "0ffh" wrote
>> Steven Schveighoffer wrote:
>>> Yeah, I'd say if you are relying on void arrays to store your pointers,
>>> you should be SOL.  If you want to use void[] to contain pointers, you
>>> should also have to maintain the pointer somewhere else as well to
>>> prevent the memory from being collected.  Can anyone give an example of
>>> where this is *necessary* and not just convenient?
>> If you want to keep extra copies of your pointers, then just do it for
>> glod's sake, and use ubyte[] for memory allocation!
>> There is no need at all  to change the behaviour of the gc WRT void[].
> I was not promoting the use of void[] to keep an only copy of a pointer.  I 
> was against it.  And I think if the gc is going to assume for *my* benefit 
> that random data I create could be a pointer, and therefore not collect data 
> it points to, then it needs to be changed.

I was not suggestung you were promoting the use of void[] to keep an only
copy of a pointer. :)
I /was/ suggesting you were suggesting to not scan void-type (=untyped)
memory blocks for pointers, and keep the pointers (or copies of them)
elsewhere to circumvent collection of life objects.
I was further suggesting that by using ubyte[] instead of void[] you
can do that already, as ubyte[] is not scanned for pointers.

> But why should the GC have to worry about pointers in random data?  My 
> question is, is there a *need* for the GC to assume any data could be a 
> pointer, does any code actually *depend* on that behavior?  I really would 
> like to see an example of where it is necessary.

Well, we are not just talking about random data, but of data which is
excplicitly defined as "data of random type, including pointers".
It is a feature, not a bug; and not incidentally, but planned this way.

> IMO conservative would be the other way around.  Conservative would be to 
> not assume something is a pointer unless it is.  I would call the current 
> behavior ... overassuming, maybe neurotic, or paranoid even? :)

It's called conservative, because if it can't tell it will err on the side
of safety.

> coder: GC, there is only random data in that block

Then call it ubyte[] to void[].
If it's void[] you are saying "here be pointers, possibly".

> GC: NO!!! it could be a POINTER!!!  THEY'RE EVERYWHERE!!!

They are! Believe me, I've seen them! =)

regards, Frank



More information about the Digitalmars-d mailing list