Git Product home page Git Product logo

Comments (12)

Raynos avatar Raynos commented on May 22, 2024

I presume you know of Gonzola's implementation

from es6-shim.

paulmillr avatar paulmillr commented on May 22, 2024

yep, I've looked at it. seems to be OK.

from es6-shim.

domenic avatar domenic commented on May 22, 2024

I think it'd be best not to have this, so people just use Maps and realize what they're getting into, instead of using WeakMaps under the perhaps-mistaken impression that the shim could be weak.

from es6-shim.

Raynos avatar Raynos commented on May 22, 2024

@DomenicDenicola the shim can be weak. Look at Gonzola's implementation, it adhere's to the weak garbage collection semantics

See blog article

from es6-shim.

paulmillr avatar paulmillr commented on May 22, 2024

I've tested WeakMap in node.js, it does proper GC. I've created 100000 objects (and weak map with them) and counted ram usage of node process. Then i've deleted objects and RAM usage has dropped to expected level.

from es6-shim.

domenic avatar domenic commented on May 22, 2024

I admit to not spending the necessary time to entirely understanding Gonzola's implementation, but it looks similar in spirit to Mark Miller's, which according to the comments has the flaw that

However, the values associated with a key in some map are retained so long as that key is retained and those associations are not overridden.

from es6-shim.

Raynos avatar Raynos commented on May 22, 2024

https://gist.github.com/1638059

I re-implemented my own flavour using gonzola's implementation as a base.

@DomenicDenicola I don't quite understand what's wrong with that. The values are retained as long as the key is retained. And as soon as the key is gone the values are gone too. That's the desired behaviour, right?

from es6-shim.

domenic avatar domenic commented on May 22, 2024

@Raynos no, the desired behavior is that neither keys nor values are held strongly. See the membrane example in Miller's comments.

from es6-shim.

paulmillr avatar paulmillr commented on May 22, 2024

So guys what do you finally think -- should es6-shim use @Raynos implementation of WeakMap even when it hold values strongly?

from es6-shim.

domenic avatar domenic commented on May 22, 2024

I vote no: people should use Maps.

The main use case for including it would be for situations where freeing the memory would be nice, if possible, but not necessary. In those cases people should do global.WeakMap = global.Map, knowing full well what they're getting into, or use a separate library. (@Raynos, perhaps you should publish a WeaklyKeyedMap repo we can refer people to?)

from es6-shim.

Raynos avatar Raynos commented on May 22, 2024

@dominic, pd.Name is a subset of weaklykeyedmap. It's more efficient and abstractions can be build on top of it. I don't intent to use a WeakMap because a Name is better.

from es6-shim.

paulmillr avatar paulmillr commented on May 22, 2024

I agree -- we should provide only 100% working shims. Mimicking API isn't good. I'll add a note to readme on weakmaps.

Thanks everyone.

from es6-shim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.