TinyBase logoTinyBase

destroy

The destroy method should be called when this Persister object is no longer used.

destroy(): Persister
returnsPersister

This guarantees that all of the listeners that the object registered with the underlying Store and storage are removed and it can be correctly garbage collected. It is equivalent to running the stopAutoLoad method and the stopAutoSave method in succession.

Example

This example creates a Store, associates a Persister object with it (that registers a TablesListener with the underlying Store), and then destroys it again, removing the listener.

const store = createStore();
const persister = createSessionPersister(store, 'pets');
await persister.startAutoSave();

console.log(store.getListenerStats().transaction);
// -> 1

persister.destroy();

console.log(store.getListenerStats().transaction);
// -> 0