Purity (D2 standard libraries / object.d)

dsimcha dsimcha at yahoo.com
Sat Jan 10 17:52:01 PST 2009


== 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?



More information about the Digitalmars-d mailing list