@@ -185,19 +185,42 @@ extension DatabasePool {
185
185
186
186
// MARK: - Memory management
187
187
188
- /// Free as much memory as possible.
188
+ /// Frees as much memory as possible, by disposing non-essential memory from
189
+ /// the writer connection, and closing all reader connections.
189
190
///
190
- /// This method blocks the current thread until all database accesses
191
- /// are completed.
191
+ /// This method is synchronous, and blocks the current thread until all
192
+ /// database accesses are completed.
193
+ ///
194
+ /// - warning: This method can prevent concurrent reads from executing,
195
+ /// until it returns. Prefer ``releaseMemoryEventually()`` if you intend
196
+ /// to keep on using the database while releasing memory.
192
197
public func releaseMemory( ) {
193
198
// Release writer memory
194
199
writer. sync { $0. releaseMemory ( ) }
200
+
195
201
// Release readers memory by closing all connections
196
202
readerPool? . barrier {
197
203
readerPool? . removeAll ( )
198
204
}
199
205
}
200
206
207
+ /// Eventually frees as much memory as possible, by disposing non-essential
208
+ /// memory from the writer connection, and closing all reader connections.
209
+ ///
210
+ /// Unlike ``releaseMemory()``, this method does not prevent concurrent
211
+ /// database accesses when it is executing. But it does not notify when
212
+ /// non-essential memory has been freed.
213
+ public func releaseMemoryEventually( ) {
214
+ // Release readers memory by eventually closing all reader connections
215
+ // (they will close after their current jobs have completed).
216
+ readerPool? . removeAll ( )
217
+
218
+ // Release writer memory eventually.
219
+ writer. async { db in
220
+ db. releaseMemory ( )
221
+ }
222
+ }
223
+
201
224
#if os(iOS)
202
225
/// Listens to UIApplicationDidEnterBackgroundNotification and
203
226
/// UIApplicationDidReceiveMemoryWarningNotification in order to release
0 commit comments