Skip to content

Commit d473ab9

Browse files
authored
Fix retain loop for enrichment plugin closure. (#262)
1 parent e613e09 commit d473ab9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/Segment/Plugins.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal protocol PlatformPlugin: Plugin { }
6868
public typealias EnrichmentClosure = (_ event: RawEvent?) -> RawEvent?
6969
public class ClosureEnrichment: Plugin {
7070
public var type: PluginType = .enrichment
71-
public var analytics: Analytics? = nil
71+
public weak var analytics: Analytics? = nil
7272

7373
internal let closure: EnrichmentClosure
7474

Tests/Segment-Tests/MemoryLeak_Tests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ final class MemoryLeak_Tests: XCTestCase {
4545
let macLifecycle = analytics.find(pluginType: macOSLifecycleEvents.self)!
4646
let macMonitor = analytics.find(pluginType: macOSLifecycleMonitor.self)!
4747
#endif
48+
49+
// test that enrichment closure isn't leaked. was previously a retain loop.
50+
analytics.add { event in
51+
return event
52+
}
4853

4954
analytics.remove(plugin: startupQueue)
5055
analytics.remove(plugin: segmentDest)

0 commit comments

Comments
 (0)