Code Monkey home page Code Monkey logo

Comments (10)

kyegupov avatar kyegupov commented on May 22, 2024 1

A note re wasm target: since webassembly has no stack introspection, marksweep cannot be ported to it. Three possible (all imperfect strategies are: manual free (incl. optionally delegating alloc/free to host), reference counting, semi-manual allocation of objects into "permanent" and "temporary" heaps.

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

The latter. All objects are allocated and never freed. However, there is a simple heap-to-stack pass that tries to allocate objects on the stack if possible so that the most obvious cases won't leak memory.

I'm planning to implement a real garbage collector at some point, probably a simple mark-sweep collector to start with. It just hasn't been done yet.

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

Closing as this is a question, not an issue. You are of course free to open an issue for GC support.

from tinygo.

Des-Nerger avatar Des-Nerger commented on May 22, 2024

Until GC is implemented, what is the preferred approach to freeing memory, for a user? Is there a temporary API for that? I feel like region-based memory management would nicely work there. Until GC is implemented, at least.

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

There is experimental GC support for ARM chips. You can enable it with -gc=marksweep.
Other than that, there is no way to free memory. However, you can structure the program in such a way that it never allocates on the heap in the main loop, by making sure everything can get stack allocated. For details, see: https://tinygo.readthedocs.io/en/latest/microcontrollers.html#heap-allocation

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

I think marksweep can be ported with some compiler work. LLVM has some support for it. It just needs to be done, and it isn't easy. See https://llvm.org/docs/GarbageCollection.html, the most likely candidate would be the shadow stack GC, at least initially.

from tinygo.

kyegupov avatar kyegupov commented on May 22, 2024

@aykevl is there any timeline/roadmap for implementing garbage collection?

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

On WebAssembly I assume?
Not really, certainly after #130 (almost finished), maybe after #104 (partially done). It's also hard to say how long the feature itself is going to take as I'm not sure how difficult it is.

from tinygo.

wilsonwang371 avatar wilsonwang371 commented on May 22, 2024

does tinygo support GC in WASM now? Do I have to call GC in my code to get memory garbage collected?

from tinygo.

aykevl avatar aykevl commented on May 22, 2024

Yes, TinyGo supports GC in WebAssembly. And you don't need to call runtime.GC for it, it happens automatically.

from tinygo.

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.