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 retain cycle(s) in encoder implementation without adding any fatalError() #221

Closed
wants to merge 2 commits into from

Conversation

betaphi
Copy link

@betaphi betaphi commented Nov 23, 2022

This PR addresses the issue #215 and serves as an alternative to #220 without adding any fatalError().

In order to confirm the fix, I have added debug output to the deinit method of EncoderImpl.

Running the test cases it clearly shows that when encoding via try encoder.encode(encodable) the deinit gets called on every test case, whereas with the old try encodable.encode(to: encoder) that is not the case.

The nested EncoderImpl are referenced weakly in a similar way as proposed in #220 in order to break retain cycles. However, instead of adding fatalError() calls when the EncoderImpl is deallocated, an error will be thrown.

@0xTim
Copy link
Member

0xTim commented Nov 23, 2022

Going in favour of #220 as it's been run in production for a while on a large site

@0xTim 0xTim closed this Nov 23, 2022
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.

2 participants