From 7d0c7e9c70fa1cfeefa7196f14b2297eb97b448f Mon Sep 17 00:00:00 2001 From: Amol Prabhu Date: Thu, 8 Aug 2024 18:56:30 -0400 Subject: [PATCH] Fix a leak related to use of function used in a closure (apollographql/apollo-ios-dev#457) --- Sources/Apollo/ApolloStore.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Apollo/ApolloStore.swift b/Sources/Apollo/ApolloStore.swift index 09729513ac..5d7d7a3c64 100644 --- a/Sources/Apollo/ApolloStore.swift +++ b/Sources/Apollo/ApolloStore.swift @@ -202,8 +202,12 @@ public class ApolloStore { public class ReadTransaction { fileprivate let cache: any NormalizedCache + + fileprivate lazy var loader: DataLoader = DataLoader { [weak self] batchLoad in + guard let self else { return [:] } + return try cache.loadRecords(forKeys: batchLoad) + } - fileprivate lazy var loader: DataLoader = DataLoader(self.cache.loadRecords) fileprivate lazy var executor = GraphQLExecutor( executionSource: CacheDataExecutionSource(transaction: self) )