Code Monkey home page Code Monkey logo

Comments (4)

AntonYudintsev avatar AntonYudintsev commented on August 15, 2024 1

That is totally correct comment, documentation is way beyond required.
Basically, there are two ways to work with memory management from c++ side, and two - from script side.
What we normally do from C++ side, is just call
context.restart();
context.restartHeaps();
on each "first run" (first in terms of call nesting, i.e. we are not calling it when script->c++->script).
That call will free all memory, and these calls are extremely cheap. With that no GC is needed at all.
The only thing required - is that there is no any global variables in script pointing to the heap (or better - no global variables at all).

The other possible way - is collect garbage (again, only from c++ side, i.e. explicit call is required). With that you can have global variables in script.

From inside script, there is option to call not only 'new', but also 'delete' (see tree benchmark).
That is unsafe, and so will require [unsafe] annotation.

We will try to make some documentation on that topic.

from dascript.

zhmt avatar zhmt commented on August 15, 2024

I prefer the the way “context.restart()” , it keep things simpler.
Thank you for your explanation!

from dascript.

AntonYudintsev avatar AntonYudintsev commented on August 15, 2024

Just don't forget restartHeaps() as well :)

from dascript.

zhmt avatar zhmt commented on August 15, 2024

Thanks for tips that will save me from bugs, I really thought a single "restart()" will work, I know the right way is calling them both:
context.restart();
context.restartHeaps();

from dascript.

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.