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 loop for enrichment plugin closure. #262

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading