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 reference cycle in LeafEncoder #216

Closed
wants to merge 2 commits into from

Conversation

dschwartz783
Copy link

This caused objects rendered in a view to be leaked, each time the view was rendered. This change breaks the reference cycle. A container should always be referenced by an encoder, so it should be safe to make the encoder reference weak, inside the container.

If anyone with more knowledge disagrees, please let me know what needs to change. Tested this in instruments, and it definitely fixes the cycle.

This caused objects rendered in a view to be leaked, each time the view is rendered.
@dschwartz783
Copy link
Author

Any update on this? This project cannot be used in anything significant as long as this ref cycle exists. Caused me some headaches in my somewhat heavily used internal project, but I'm using my own branch for now. Let me know if something needs to change!

@@ -135,7 +135,7 @@ extension LeafEncoder {
}

private final class KeyedContainerImpl<Key>: KeyedEncodingContainerProtocol, LeafEncodingResolvable where Key: CodingKey {
private let encoder: EncoderImpl
private weak var encoder: EncoderImpl!
Copy link
Member

@0xTim 0xTim Sep 27, 2022

Choose a reason for hiding this comment

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

We can't force unwrap these here - if they're weak then there's a chance that the reference will have been released when we try and use them, which will take down a server. So we'll need to check they exist where we use them

@0xTim
Copy link
Member

0xTim commented Nov 22, 2022

Closing in favour of #220

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.

None yet

2 participants