Skip to content

Commit 0695f18

Browse files
wilhuffCorrob
authored andcommitted
Avoid retain cycles in parent pointers (#2621)
All the various table drivers that need to navigate back must use weak pointers to get there because the parent owns the children.
1 parent 6526073 commit 0695f18

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Firestore/core/src/firebase/firestore/local/leveldb_remote_document_cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class LevelDbRemoteDocumentCache : public RemoteDocumentCache {
5757
FSTMaybeDocument* DecodeMaybeDocument(absl::string_view encoded,
5858
const model::DocumentKey& key);
5959

60-
FSTLevelDB* db_;
60+
// This instance is owned by FSTLevelDB; avoid a retain cycle.
61+
__weak FSTLevelDB* db_;
6162
FSTLocalSerializer* serializer_;
6263
};
6364

Firestore/core/src/firebase/firestore/local/memory_mutation_queue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class MemoryMutationQueue : public MutationQueue {
111111
*/
112112
int IndexOfBatchId(model::BatchId batch_id);
113113

114-
FSTMemoryPersistence* persistence_;
114+
// This instance is owned by FSTMemoryPersistence; avoid a retain cycle.
115+
__weak FSTMemoryPersistence* persistence_;
115116
/**
116117
* A FIFO queue of all mutations to apply to the backend. Mutations are added
117118
* to the end of the queue as they're written, and removed from the front of

Firestore/core/src/firebase/firestore/local/memory_query_cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class MemoryQueryCache : public QueryCache {
9595
void SetLastRemoteSnapshotVersion(model::SnapshotVersion version) override;
9696

9797
private:
98-
FSTMemoryPersistence* persistence_;
98+
// This instance is owned by FSTMemoryPersistence; avoid a retain cycle.
99+
__weak FSTMemoryPersistence* persistence_;
100+
99101
/** The highest sequence number encountered */
100102
model::ListenSequenceNumber highest_listen_sequence_number_;
101103
/** The highest numbered target ID encountered. */

Firestore/core/src/firebase/firestore/local/memory_remote_document_cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class MemoryRemoteDocumentCache : public RemoteDocumentCache {
6262
/** Underlying cache of documents. */
6363
model::MaybeDocumentMap docs_;
6464

65-
FSTMemoryPersistence *persistence_;
65+
// This instance is owned by FSTMemoryPersistence; avoid a retain cycle.
66+
__weak FSTMemoryPersistence *persistence_;
6667
};
6768

6869
} // namespace local

0 commit comments

Comments
 (0)