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

Use expression body #3491

Merged
merged 4 commits into from Apr 15, 2020
Merged

Use expression body #3491

merged 4 commits into from Apr 15, 2020

Conversation

yahiheb
Copy link
Collaborator

@yahiheb yahiheb commented Apr 5, 2020

Note that I changed the LoadCommand property's type in order to use expression body:
public ReactiveCommand<Unit, Unit> LoadCommand { get; }
public ReactiveCommand<Unit, IDisposable> LoadCommand { get; }

Is that safe to do? I tested and everything seems to work properly.

@yahiheb yahiheb changed the title Use expression body for accessors Use expression body Apr 5, 2020
@pull-request-size pull-request-size bot added size/M and removed size/S labels Apr 5, 2020
});
}, this.WhenAnyValue(x => x.SelectedWallet, x => x?.WalletState).Select(x => x == WalletState.Uninitialized));
LoadCommand = ReactiveCommand.Create(() =>
RxApp.MainThreadScheduler.Schedule(async () => await LoadWalletAsync()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out this is disposable. Can you add CompositDisposables property and add this and RootList to it and dispose the CompositDisposables in the Dispose method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yahiheb this is what I meant. Every time you initialize a new object which is IDisposable you should consider adding the disposal of it. If the disposal is missing you will get a memory leak, if the disposal is there nothing happens.
Rx has a different approach to this: you only have to dispose of if you are subscribing to a non-class member object. In this case, we might not need to dispose of the IDisposable created by Schedule but I am not sure.

https://stackoverflow.com/questions/58026600/should-i-dispose-ischeduler-schedule-subscription-mannualy-to-avoid-memory-leaks

@danwalmsley I got some ideas after reading that. How about adding RxApp.TaskpoolScheduler to the ReactiveCommand and remove the Schedule?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molnard Thank you very much.
I appreciate your explanation and your help.

@molnard
Copy link
Collaborator

molnard commented Apr 12, 2020

Ready to review!

@molnard molnard merged commit d6c683f into zkSNACKs:master Apr 15, 2020
@yahiheb yahiheb deleted the expression-body branch April 15, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants