Skip to content

Commit

Permalink
Avoid releasing retainables if there are pending writes (#1589)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1589

Avoid releasing retainables at the end of the batch if there were writes while processing them.  This could happen, for example, if there are effects which monitor changes and then also write state.

This error is currently superfulous for the open source release where garbage collection is enabled but not used.

Addresses #1582

Reviewed By: davidmccabe

Differential Revision: D33965759

fbshipit-source-id: 904f6e1778f7ba864cea54f0e3f2641e995834c1
  • Loading branch information
drarmstr authored and facebook-github-bot committed Feb 6, 2022
1 parent 28c1387 commit b89eb6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## UPCOMING

- Avoid spurious console errors from effects when calling `setSelf()` from `onSet()` handlers. (#1589)

**_Add new changes here as they land_**

- `shouldNotBeFrozen` now works in JS environment without `Window` interface. (#1571)
Expand Down
8 changes: 6 additions & 2 deletions packages/recoil/core/Recoil_RecoilRoot.js
Expand Up @@ -209,7 +209,7 @@ function endBatch(store: Store) {

// Ignore commits that are not because of Recoil transactions -- namely,
// because something above RecoilRoot re-rendered:
if (nextTree === null) {
if (nextTree == null) {
return;
}

Expand All @@ -232,7 +232,11 @@ function endBatch(store: Store) {
storeState.previousTree = null;

if (gkx('recoil_memory_managament_2020')) {
releaseScheduledRetainablesNow(store);
// Only release retainables if there were no writes during the end of the
// batch. This avoids releasing something we might be about to use.
if (nextTree == null) {
releaseScheduledRetainablesNow(store);
}
}
} finally {
storeState.commitDepth--;
Expand Down

0 comments on commit b89eb6d

Please sign in to comment.