GDScript: Respect external refs when cleaning up cyclic refs #114651
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alternative to #114801
Fixes #114420
Fixes #98141 (tested using the 4.3 MRP by myself. Not the original one.)
Supersedes #114623
Might be related to: #95428 -> No MRP, but my hypothesis is, that script members were cleared from a still referenced script.
When a GDScript is freed it searches for cycles refs amongst its dependencies and clears those as well. However the current implementation does not account for cases were certain scripts are still referenced but by something that is not GDScript. The only indication we have of such a reference is the refcount which the current algorithm does never even look at.
This PR introduces a new approach:
unreferenceto actually trigger, that's not an issue with this PR though,GDScriptCacheholds references to all scripts so they only get destructed in rare cases