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

Add details about hidden leaks. #97

Merged
merged 14 commits into from
Jul 21, 2023
Merged

Add details about hidden leaks. #97

merged 14 commits into from
Jul 21, 2023

Conversation

polina-c
Copy link
Contributor

No description provided.

@polina-c polina-c requested a review from CoderDake as a code owner July 19, 2023 18:39
doc/TROUBLESHOOT.md Outdated Show resolved Hide resolved
doc/TROUBLESHOOT.md Outdated Show resolved Hide resolved
doc/TROUBLESHOOT.md Outdated Show resolved Hide resolved
Comment on lines 113 to 115
And, there is no point to release reference to child inside the method `dispose` of the parent, because
not needed parent should be released together with its disposal. If
your fix for a leak is like this, you are defenitely hiding the leak:
Copy link

Choose a reason for hiding this comment

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

I'm not sure this is true.

If the child is not nulled out, it may not be eligible for garbage collection (even if it has released some resource in dispose). And if it is not nulled out, other code in the class that depends on its nullability to determine whether it can be used or not may fail.

For example, it's pretty common in Flutter code to mark some native object as nullable, and once it is disposed null it out so it doesn't get used again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not saying it is wrong to null out. I am saying it is wrong to null out in dispose.
If parent is disposed, it should become non-used, unreachable and thus to be garbage collected together with child.

Another side effect of nulling in dispose is that you have to make the field nullable, that adds unnecessary complexity to the code and eliminates non-nullable optimizations.

How does it sound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, when leak_tracker checks that disposed members are garbage collected, this nulling out is not needed.

Copy link

Choose a reason for hiding this comment

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

Nulling it out in dispose helps with assertions and error checking that the parent and child objects are getting used correctly. It also helps avoid runtime errors due to misuse in some cases, where a null check can guard things even if asserts are disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. There are pros and cons nulling out member in dispose.

However, the statement here is: a leak fix should not be nulling out in dispose, because, while it makes the leak smaller, it does not fix it.

This means it is ok to null out the member in dispose in a separate PR, but not in order to fox the leak. Am I missing something?

Copy link

Choose a reason for hiding this comment

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

Yeah, I think pointing out that nulling it out isn't the right way to fix the leak, but I would avoid calling that style bad - it's used frequently in the flutter framework for the reasons I mentioned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified. Is it better now?

doc/TROUBLESHOOT.md Outdated Show resolved Hide resolved
doc/TROUBLESHOOT.md Show resolved Hide resolved
polina-c and others added 3 commits July 20, 2023 10:39
Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com>
@polina-c polina-c merged commit 2152aab into main Jul 21, 2023
2 checks passed
@polina-c polina-c deleted the polina-c-patch-1 branch July 21, 2023 16:02
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.

3 participants