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

Weak in electron: works in main, fails in renderer -- why? #86

Open
3n-mb opened this issue Jan 24, 2018 · 3 comments
Open

Weak in electron: works in main, fails in renderer -- why? #86

3n-mb opened this issue Jan 24, 2018 · 3 comments

Comments

@3n-mb
Copy link

3n-mb commented Jan 24, 2018

The following has been observed. weak can be built and used in electron app, as long as import/require is done in main process. If weak is require-d in renderer, renderer process crashes when registered object is garbage collected.
Why?
And should it work in renderer, or, of cause it shouldn't?

@TooTallNate
Copy link
Owner

To be honest, I'm not really sure about the implementation details of Electron's renderer process, though I know that they do some magic bridging that might be getting in the way. You might need to check with them if there's something special that needs to be done.

@martijnthe
Copy link

@3n-mb seeing a similar thing. Have you learned anything new in the mean time?

@3n-mb
Copy link
Author

3n-mb commented Feb 8, 2018

@martijnthe I have no info about why this happens. But I have a working horrible hack that allows to have weak-like functionality in renderer. It goes like this:

Workaround

  • Electron's rmi works with the following rule: when renderer gives object to main, main will have a shadow (proxy) of it, as long as a reference in renderer is alive.
  • In main, we make a weak service, exposed to renderer via rmi: added to global on main side, and used in renderer via remote.getGlobal(name).
  • This weak service in main uses weak module, in which objects (as proxy shadows) are given from renderer along with callbacks, defined and executed in renderer.

Electron's rmi has ability to track objects in renderer and react (callback something) when they are gone. May be, one may find in code how it is done, hopefully in js, but the rabbit hole may go all the way to atom.binding.
The hack is horrible only in its double use of reference tracking (in rmi and in weak), and a fact that callbacks are done over the slower boundary, which may not matter for slower code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants