Purity (D2 standard libraries / object.d)

Walter Bright newshound1 at digitalmars.com
Sat Jan 10 18:49:58 PST 2009


dsimcha wrote:
> == Quote from Walter Bright (newshound1 at digitalmars.com)'s article
>> dsimcha wrote:
>>> In this case, foo.myInvariantArray goes out of scope when foo() returns.  When
>>> bar() allocates an array, it's entirely possible that the GC will give bar.myArray
>>> the same memory address as foo.myArray had.  In this case, if you're only using
>>> stack bits to handle memoization, you're screwed.
>> That's the beauty of a garbage collector <g>. The bits will include a
>> reference to the immutable data, which the gc will see, and so the gc
>> will not reclaim that data.
> 
> Good point, the bits in the internal memoization AA will contain a reference.  I
> forgot about that.  This leads to another problem, though:  Wouldn't this cause a
> lot of soft memory leaks, since you're holding references to stuff that's
> otherwise no longer needed?

The job of managing those kind of design tradeoffs is something that the 
programmer should handle.



More information about the Digitalmars-d mailing list