From 555c14956a3a67398ecb6ea756936db36cb17c40 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Sat, 21 Oct 2017 15:44:33 -0700 Subject: [PATCH] Fix retain cycle between Parser and ParserATNSimulator. This was causing the entire parser to be retained, resulting in a large memory leak. This fix simply changes the reference from ParserATNSimulator to Parser to be unowned. Ditto between Lexer and LexerATNSimulator, except this reference is made weak because LexerATNSimulator.recog is nullable. (That difference is dubious IMHO, but I'm leaving it intact for now.) --- runtime/Swift/Sources/Antlr4/atn/LexerATNSimulator.swift | 2 +- runtime/Swift/Sources/Antlr4/atn/ParserATNSimulator.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/Swift/Sources/Antlr4/atn/LexerATNSimulator.swift b/runtime/Swift/Sources/Antlr4/atn/LexerATNSimulator.swift index 9db7e1de6..5f7f619bf 100644 --- a/runtime/Swift/Sources/Antlr4/atn/LexerATNSimulator.swift +++ b/runtime/Swift/Sources/Antlr4/atn/LexerATNSimulator.swift @@ -50,7 +50,7 @@ open class LexerATNSimulator: ATNSimulator { } - internal let recog: Lexer? + internal weak var recog: Lexer? /// /// The current token's starting index into the character stream. diff --git a/runtime/Swift/Sources/Antlr4/atn/ParserATNSimulator.swift b/runtime/Swift/Sources/Antlr4/atn/ParserATNSimulator.swift index fb0ce0341..ca58b56ef 100644 --- a/runtime/Swift/Sources/Antlr4/atn/ParserATNSimulator.swift +++ b/runtime/Swift/Sources/Antlr4/atn/ParserATNSimulator.swift @@ -250,7 +250,8 @@ open class ParserATNSimulator: ATNSimulator { } return false }() - internal final var parser: Parser + + internal final unowned let parser: Parser public final var decisionToDFA: [DFA]