Skip to content

Commit 8b54ab1

Browse files
author
Michel Weststrate
committed
docs: clarify memory leaks when using objects as keyed collecitons.
1 parent 09703d6 commit 8b54ab1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/observable-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Doubler {
6969
**All annotated** fields are **non-configurable**.<br>
7070
**All non-observable** (stateless) fields (`action`, `flow`) are **non-writable**.
7171

72-
7372
<!--class + decorators-->
7473

7574
When using modern decorators, there is no need to call `makeObservable`, below is what a decorator based class looks like.
@@ -148,7 +147,6 @@ tags.push("prio: for fun")
148147
In contrast to the first example with `makeObservable`, `observable` supports adding (and removing) _fields_ to an object.
149148
This makes `observable` great for collections like dynamically keyed objects, arrays, Maps and Sets.
150149

151-
152150
<!--class + decorators (legacy)-->
153151

154152
To use legacy decorators, `makeObservable(this)` should be called in the constructor to make sure decorators work.
@@ -222,6 +220,8 @@ The object returned by `observable` will be a Proxy, which means that properties
222220

223221
The `observable` method can also be called with collections types like [arrays](api.md#observablearray), [Maps](api.md#observablemap) and [Sets](api.md#observableset). Those will be cloned as well and converted into their observable counterparts.
224222

223+
> Tip: as holds for JavaScript in general, don't use observable plain objects to create a keyed collection (for example to store a mapping from a user's UUID to user object), use maps instead. Object descriptors are aggressively cached by MobX, so if property names are unstable, this might result in memory leaks.
224+
225225
<details id="observable-array"><summary>**Example:** observable array<a href="#observable-array" class="tip-anchor"></a></summary>
226226

227227
The following example creates an observable and observes it using [`autorun`](reactions.md#autorun).

0 commit comments

Comments
 (0)