Skip to content

Commit

Permalink
Fix retain loop for enrichment plugin closure.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Oct 25, 2023
1 parent e613e09 commit 4b77bd2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Segment/Plugins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal protocol PlatformPlugin: Plugin { }
public typealias EnrichmentClosure = (_ event: RawEvent?) -> RawEvent?
public class ClosureEnrichment: Plugin {
public var type: PluginType = .enrichment
public var analytics: Analytics? = nil
public weak var analytics: Analytics? = nil

internal let closure: EnrichmentClosure

Expand Down
5 changes: 5 additions & 0 deletions Tests/Segment-Tests/MemoryLeak_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ final class MemoryLeak_Tests: XCTestCase {
let macLifecycle = analytics.find(pluginType: macOSLifecycleEvents.self)!
let macMonitor = analytics.find(pluginType: macOSLifecycleMonitor.self)!
#endif

// test that enrichment closure isn't leaked. was previously a retain loop.
analytics.add { event in
return event
}

analytics.remove(plugin: startupQueue)
analytics.remove(plugin: segmentDest)
Expand Down

0 comments on commit 4b77bd2

Please sign in to comment.