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
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Leaf/LeafEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

private var data: [String: LeafEncodingResolvable] = [:]

/// See ``LeafEncodingResolvable/resolvedData``.
Expand Down Expand Up @@ -196,7 +196,7 @@ extension LeafEncoder {
}

private final class UnkeyedContainerImpl: UnkeyedEncodingContainer, LeafEncodingResolvable {
private let encoder: EncoderImpl
private weak var encoder: EncoderImpl!
private var data: [LeafEncodingResolvable] = []

/// See ``LeafEncodingResolvable/resolvedData``.
Expand Down