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

Make it possible to prevent garbage collection of CodeBehind class #430

Open
lestard opened this Issue Aug 10, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@lestard
Collaborator

lestard commented Aug 10, 2016

In some situations a JavaFX controller class (CodeBehind) can be garbage collected which can be unexpected. This is especially true for the MVVM pattern were the focus is on binding ui controls to properties of the ViewModel. Because normal databinding uses weak references internally this can lead to wrong behaviour of the application because the code behind and the viewModel are garbage collected.

See issue #429 and this gist for examples.

The purpose of this issue is:

  1. Document the behavior and the reasons for garbage collection
  2. Think about utilities that the framework can provide to prevent this behavior.

Our viewloader could keep references to codebehind instances so that they aren't available for garbage collection anymore. However, this would lead to memory leaks because there are many situations were a codeBehind should be garbage collected (for example when an extra window is closed all resources of this window should be collected).

This means that we can't prefent garbage collection for all codeBehinds. Instead we could provide an extra mechanism to the developer to explicitly declare that a codeBehind shouldn't be garbage collected.

One way of doing this could be an interface PreventGC (maybe we find another name) that our viewLoader recognizes.

This interface could have a method default void release() that can be invoked by the developer at a later point in time when the codeBehind isn't used anymore and can now be collected by the garbage collector. This way the developer has more control over this process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment