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

Fix Garbage Collection of Delegates #106

Merged
merged 2 commits into from
Nov 11, 2020
Merged

Fix Garbage Collection of Delegates #106

merged 2 commits into from
Nov 11, 2020

Conversation

mjakeman
Copy link
Member

@mjakeman mjakeman commented Nov 11, 2020

Keeps a reference to any delegates we use to avoid upsetting the garbage collector when low on RAM.

The culprits seem to be the following two delegates, which I've gone ahead and fixed:

  • MarshalCallback in ClosureHelper.cs
  • OnFinalized in Object.cs

I'm not finding anything else, but if we do encounter this later the fix is rather straightforward. We can avoid this by holding a strong reference to any delegates we pass to GLib.

Fixes #82

Keeps a reference to the MarshalCallback delegate to
prevent the Garbage Collector from collecting it while
still in use.

Partially fixes #82
Stops the Garbage Collector from collecting the
WeakNotify delegate used by Object.cs to dispose
of unmanaged resources.

This should be the last instance of garbage collected
delegates, but the fix is quite simple if we encounter
this issue again.

Fixes #82
@mjakeman mjakeman requested a review from a team November 11, 2020 07:22
Copy link
Member

@badcel badcel left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you.

Copy link
Member

@na2axl na2axl left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏾

@na2axl na2axl merged commit dab299b into gircore:develop Nov 11, 2020
@mjakeman mjakeman deleted the fix/delegates branch November 11, 2020 21:54
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

Successfully merging this pull request may close these issues.

Garbage Collection frees needed objects
3 participants