memory safety and weak references

Mark S. Miller erights at google.com
Mon Apr 1 15:03:49 PDT 2013


On Mon, Apr 1, 2013 at 2:56 PM, Brendan Eich <brendan at mozilla.com> wrote:

> Hudson, Rick wrote:
>
>>
>> This brings up another interesting point. Do WeakRefs change a compiler’s
>> liveness analysis?
>>
>>
> Yes, of course.
>
>
>  This could complicate some apparently useful optimizations.
>>
>> {
>>
>> var x = new Something();
>>
>> someWeakRef.set(x);
>>
>> // Is x dead? (yes) Is x required to contribute to the root set? (I hope
>> not.)
>>
>>
> You dind't kill x yet. Did you forget
>
> x = null;
>
> here?
>
>
>  gc();
>>
>> someWeakRef.get() // null or foo?
>>
>>
> If x = null; happened before gc() then null else the original ref.


Not necessarily. For example, a conservative gc might not be able to see
that foo is no longer actually reachable. <
http://wiki.ecmascript.org/doku.php?id=strawman:gc_semantics> explains that
this is why it states such matters as SHOULDs rather than MUSTs.

Of course, if we imagine a gc() function with a stronger contract, then the
above would follow. I am skeptical that we could ever state such a stronger
contract that all JS implementors could agree to.

-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130401/48c9f32d/attachment-0001.html>


More information about the es-discuss mailing list