Skip to content

Commit 6ab90a0

Browse files
committed
Document releaseMemoryEventually and automaticMemoryManagement
1 parent 23fa42a commit 6ab90a0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7718,12 +7718,36 @@ dbPool.releaseMemory()
77187718
77197719
This method blocks the current thread until all current database accesses are completed, and the memory collected.
77207720
7721+
> :warning: **Warning**: If `DatabasePool.releaseMemory()` is called while a long read is performed concurrently, then no other read access will be possible until this long read has completed, and the memory has been released. If this does not suit your application needs, look for the asynchronous options below:
7722+
7723+
You can release memory in an asynchronous way as well:
7724+
7725+
```swift
7726+
// On a DatabaseQueue
7727+
dbQueue.asyncWriteWithoutTransaction { db in
7728+
db.releaseMemory()
7729+
}
7730+
7731+
// On a DatabasePool
7732+
dbPool.releaseMemoryEventually()
7733+
```
7734+
7735+
`DatabasePool.releaseMemoryEventually()` does not block the current thread, and does not prevent concurrent database accesses. In exchange for this convenience, you don't know when memory has been freed.
7736+
77217737
77227738
### Memory Management on iOS
77237739
77247740
**The iOS operating system likes applications that do not consume much memory.**
77257741
7726-
[Database queues](#database-queues) and [pools](#database-pools) automatically call the `releaseMemory` method when the application receives a memory warning, and when the application enters background.
7742+
[Database queues](#database-queues) and [pools](#database-pools) automatically free non-essential memory when the application receives a memory warning, and when the application enters background.
7743+
7744+
You can opt out of this automatic memory management:
7745+
7746+
```swift
7747+
var config = Configuration()
7748+
config.automaticMemoryManagement = false
7749+
let dbQueue = try DatabaseQueue(path: dbPath, configuration: config) // or DatabasePool
7750+
```
77277751
77287752
77297753
## Data Protection

0 commit comments

Comments
 (0)