Garbage collector memory leak "feature"?

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 10 08:39:15 PDT 2007


"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 personally don't use void[] for anything because I don't see the need for 
it in my code, but I can't make other libraries that I use change their 
code.

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.

>
>> Would it be possible to allow for optimizations for people who are not 
>> interested in garbage collection, but are interested in speed/mem usage,
>> to use some other memory allocation scheme that does not use the garbage
>>  collector?  Then throw away the assumptions that have caused these
>> leaks to occur (e.g. void[] can contain pointers)?
>
> IIRC just use std.c.malloc to get unmanaged memory blocks.

Cool.  So there is a way to do this, and therefore the garbage collector can 
use more memory if it needs to in order to not leak memory, and people who 
want less memory usage/speed could use malloc.

>
>> to me, gc-that-leaks-memory-by-assuming-random-data-is-a-pointer ==
>> broken gc.  Speed/mem usage is secondary.
>
> Well, the rest of us calls it "conservative garbage collector"... =)

So it's fine with you if your application keeps crashing every 2 days 
because it gradually leaks all the memory on your system?  I'm sure that 
will do wonders for the adoption of D.

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? :)

coder: GC, there is only random data in that block
GC: NO!!! it could be a POINTER!!!  THEY'RE EVERYWHERE!!!

-Steve 





More information about the Digitalmars-d mailing list