@@ -60,9 +60,13 @@ class Store {
60
60
/// A list of observers of the Store.close() event.
61
61
final _onClose = < dynamic , void Function ()> {};
62
62
63
- /// If weak and calling [close] does not try to close the native Store and
63
+ /// If true and calling [close] will also close the native Store and
64
64
/// remove [_absoluteDirectoryPath] from [_openStoreDirectories] .
65
- final bool _weak;
65
+ final bool _closesNativeStore;
66
+
67
+ /// If true and calling [close] will also close a cached WeakStore, if one was
68
+ /// created for this store.
69
+ final bool _closesWeakStore;
66
70
67
71
/// Default value for string query conditions [caseSensitive] argument.
68
72
final bool _queriesCaseSensitiveDefault;
@@ -153,7 +157,8 @@ class Store {
153
157
bool queriesCaseSensitiveDefault = true ,
154
158
String ? macosApplicationGroup})
155
159
: _defs = modelDefinition,
156
- _weak = false ,
160
+ _closesNativeStore = true ,
161
+ _closesWeakStore = true ,
157
162
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault,
158
163
directoryPath = _safeDirectoryPath (directory),
159
164
_absoluteDirectoryPath =
@@ -269,8 +274,10 @@ class Store {
269
274
/// ```
270
275
Store .fromReference (this ._defs, this ._reference,
271
276
{bool queriesCaseSensitiveDefault = true })
272
- // must not close the same native store twice so [_weak]=true
273
- : _weak = true ,
277
+ :
278
+ // Must not close native store twice, only original store is allowed to.
279
+ _closesNativeStore = false ,
280
+ _closesWeakStore = true ,
274
281
directoryPath = '' ,
275
282
_absoluteDirectoryPath = '' ,
276
283
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault {
@@ -297,7 +304,9 @@ class Store {
297
304
/// See [_clone] for details.
298
305
Store ._minimal (int ptrAddress, {bool queriesCaseSensitiveDefault = true })
299
306
: _defs = null ,
300
- _weak = false ,
307
+ _closesNativeStore = true ,
308
+ // Minimal store does not have a model, so could not create Weak Store.
309
+ _closesWeakStore = false ,
301
310
directoryPath = '' ,
302
311
_absoluteDirectoryPath = '' ,
303
312
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault {
@@ -322,8 +331,8 @@ class Store {
322
331
/// is closed (e.g. when the app exits).
323
332
Store .attach (this ._defs, String ? directoryPath,
324
333
{bool queriesCaseSensitiveDefault = true })
325
- // _weak = false so store can be closed.
326
- : _weak = false ,
334
+ : _closesNativeStore = true ,
335
+ _closesWeakStore = true ,
327
336
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault,
328
337
directoryPath = _safeDirectoryPath (directoryPath),
329
338
_absoluteDirectoryPath =
@@ -368,7 +377,9 @@ class Store {
368
377
Store ._fromWeakStore (
369
378
StoreConfiguration configuration, Pointer <OBX_weak_store > weakStorePtr)
370
379
: _defs = configuration.modelDefinition,
371
- _weak = false ,
380
+ _closesNativeStore = true ,
381
+ // This Store was obtained from a WeakStore, do not close it.
382
+ _closesWeakStore = false ,
372
383
directoryPath = configuration.directoryPath,
373
384
_absoluteDirectoryPath = '' ,
374
385
_queriesCaseSensitiveDefault =
@@ -499,7 +510,12 @@ class Store {
499
510
500
511
_reader.clear ();
501
512
502
- if (! _weak) {
513
+ if (_closesWeakStore) {
514
+ // If there is a weak store reference for this, close it as well.
515
+ WeakStore .get (configuration ())? .close ();
516
+ }
517
+
518
+ if (_closesNativeStore) {
503
519
_openStoreDirectories.remove (_absoluteDirectoryPath);
504
520
final errors = List .filled (2 , 0 );
505
521
if (_cFinalizer != nullptr) {
0 commit comments