Skip to content

Clarifying weak caching vs manual management #3820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
The answer is out there
line 469 is as smart question,
needs to be answered

we dont manage everything oourselves 
like we dont put x y window coordinates on the screen anymore
  • Loading branch information
joaquinelio authored Feb 22, 2025
commit 207fdda8aab1f541ce71a1db731bf800b62f113b
4 changes: 3 additions & 1 deletion 1-js/99-js-misc/07-weakref-finalizationregistry/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ Of course, it is important to remember, that such behavior is not guaranteed, an
Based on this, a completely logical question immediately arises: why do not we use an ordinary cache, where we can manage its entities ourselves, instead of relying on the garbage collector?
That's right, in the vast majority of cases there is no need to use `WeakRef` and `FinalizationRegistry`.

We don’t always manage manually because we no longer program for fixed hardware; we delegate to the engine, which adjusts behavior based on available resources. We use this approach when we suspect, as in this case, that memory management might be an issue, allowing for a more flexible and adaptable implementation.

Here, we simply demonstrated an alternative implementation of similar functionality, using a non-trivial approach with interesting language features.
Still, we cannot rely on this example, if we need a constant and predictable result.

Expand All @@ -480,4 +482,4 @@ You can [open this example in the sandbox](sandbox:weakref-finalizationregistry)
This is beneficial for addressing excessive memory usage and optimizing the utilization of system resources in applications.

`FinalizationRegistry` - is a tool for registering callbacks, that are executed when objects that are no longer strongly referenced, are destroyed.
This allows releasing resources associated with the object or performing other necessary operations before deleting the object from memory.
This allows releasing resources associated with the object or performing other necessary operations before deleting the object from memory.