OSNews article about C++09 degenerates into C++ vs. D discussion
Kyle Furlong
kylefurlong at gmail.com
Sun Nov 19 20:24:15 PST 2006
Bill Baxter wrote:
> Julio César Carrascal Urquijo wrote:
>> Mars wrote:
>>> http://www.osnews.com/comment.php?news_id=16526
>>
>> This is one thing that bothers me with the current GC. If you store
>> data with a lot of entropy in an array (Sound, encrypted data, sensor
>> data, etc...) you start to experience memory leaks because the GC
>> starts to see the data as references to other objects.
>
> This is the kind of comment that scares me.
> How does one reconcile this with Walter's comment "The GC has been
> pretty heavily tested. It's 6 years old, and it's stood up extremely well."
> --(digitalmars.com digitalmars.D:43916)
>
> --bb
The problem is that if the data isn't typed, the GC cannot say
absolutely that the data is not pointers into the GC allocated space.
Since a collector that freed all these "ambiguous" roots would
eventually free live objects, one must treat these roots as pointers.
The good news is that most data that falls into this category is
temporary, such that the region kept alive by the false pointer will be
freed on a subsequent collection.
Now in the case of arrays, I think that probably the current collector
is being far too conservative. Since each array is typed, with the
exception of void[], the GC should differentiate between, for example, a
byte[] and a Class[] or void*[] and treat them appropriately.
So the solution for your example is to store the data not in a void[]
but in a more appropriately typed container, possibly byte[]. Of course
the optimal solution depends on your application.
More information about the Digitalmars-d
mailing list