Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better memory model #381

Open
almarklein opened this issue Jun 13, 2017 · 0 comments
Open

Better memory model #381

almarklein opened this issue Jun 13, 2017 · 0 comments

Comments

@almarklein
Copy link
Member

This is a preliminary proposal on how to manage memory in the new Flexx (as proposed in #367).

The proposal in #367 defines PyComponents and JSComponents, each living either in JS or Py. The JSComponents can be "referenced" in Py (instantiate, observe events, invoke actions), but nothing more. Each side will have its own memory management system. (In the current system all Model objects live both in Py and JS, making memory management somewhat ... entangled.)

For PyComponents, we can use the normal Python gc. Use weak reference to store handlers and properly dispose when __del__ is called.

For JSComponents we have to do more work. There are no weak references in JS, so objects are sorta bound to get "stuck". One option would be to let the user explicitly call dispose() on unused widgets, though that feels a bit like C. Another is to implement a simple tracing GC (local to Flexx-component-land) that checks what components are "reachable" from the root models. This means very little worries for the user, except that in order to prevent an object (e.g. an orphaned widget) from being deleted, it has to be kept in a place where the Flexx gc can find it (e.g. a private property (not attribute) on another component).

Any JSComponents instantiated in Python can perhaps be auto-disposed via Python's gc.

When a component is disposed, it should be "destructed" automatically, by nulling all properties, so that the JS gc can clean things up. No events should be emitted. It is the responsibility of the user to make sure that the object is not used anywhere when dispose() is used explicitly.

@almarklein almarklein added this to the v0.5 milestone Jun 13, 2017
@almarklein almarklein modified the milestones: v0.5, v0.6 Mar 21, 2018
@almarklein almarklein modified the milestones: v0.6, v1.0 Oct 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant