memory safety and weak references

Brendan Eich brendan at mozilla.com
Mon Apr 1 14:56:06 PDT 2013


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.

/be

>>
> }
>


More information about the es-discuss mailing list