Skip to content
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

Let JS garbage collection handle removed assets #955

Open
Munter opened this issue Dec 13, 2018 · 2 comments
Open

Let JS garbage collection handle removed assets #955

Munter opened this issue Dec 13, 2018 · 2 comments

Comments

@Munter
Copy link
Member

Munter commented Dec 13, 2018

Currently Assetgraph keeps a reference to all added assets. It keeps these references alive even when the last incoming relation to an asset is removed from the graph, essentially orphaning the asset. This is quite surprising from an end user perspective.

Suggestion

Stop tracking all assets in a Set in the AssetGraph instance. Instead, create a new Set of entry points, create a method called addEntryPoint that adds an Asset or assetConfiguration to the entry point set, and then change all findAssets-like functionality to use a graph traversal from the entry point set rather than filtering the now deprecated AssetGraph._assets Set.

Upsides

Assets that are disconnected are no longer in the graph and will eventually be garbage collected.

This is a more intuitive interface, since all normal programming works in a way where things are cleaned up once you no longer keep a reference to them in your current scope, unless you reconnect a reference to them somewhere

TODO

Figure out if this has major performance implications

@papandreou
Copy link
Member

Thought a bit about this. One challenge is how to figure out whether a given url is already in the graph. We can't really keep a url => asset index like we do now, because then we would retain a reference to the asset that then wouldn't be GCed. I think traversing the entire graph would be the only option 😟

@Martin-Pitt
Copy link

WeakSet and WeakMap allow for garbage collectable data structures.

They have some gotchas, e.g. they are not iterable themselves. However, there are ways to work around that. For example having a Set/Array that tracks all key names, then using .has() during iteration to check if it's still live, otherwise flush it from the known keys — a kind of manual GC check in a way :)

With the _urlIndex it looks like it doesn't require it to be iterable, the .set()/.get() / .has() & .delete() methods do everything it needs to in that file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants