Skip to content
New issue

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

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

Already on GitHub? # to your account

Binding Cache is filled and not purged, Memory grows #146

Closed
simonbuehler opened this issue Jun 6, 2020 · 5 comments
Closed

Binding Cache is filled and not purged, Memory grows #146

simonbuehler opened this issue Jun 6, 2020 · 5 comments

Comments

@simonbuehler
Copy link
Contributor

hi,

binding a c# Property to JS adds a Cache Entry to the Dictionary on each change leading to a ever growing Memory Usage.

  • Why is there a cache for Properties in the first place? I can't see a obvious benefit of having old cached property values?
  • There should be either a [nocaching] Attribute which would not cache a Property or the cache should be purged somehow

a short explanation would be great!

@David-Desmaisons
Copy link
Member

Let me try to explain:
-Neutronium maintains a mapping between C# Vm and javascript object
-To do so it has a dictionnary where the key is the C# object and the value is a binding object
-This dictionary is crucial to deal with one to one mapping and features as circular references

  • Neutronium is using a garbage-like counting reference mechanism to purge this dictionary when a Vm object is no more needed in the UI.
  • This mechanism is implemented for complex type but not for boolean, numbers and string
  • In "standard" scenario the memory usage due to this dictionary is not a problem

So basically, here the possible solutions I can image consist in:

  1. Extend counting reference for all types. Drawback: will impact badly performance: by the need to the remoce the entry and not caching anymore a result
  2. Alternativelly try to use weakrefrence at some points

Both are feasible but rather none-trivial tasks, I will need some time to investigate.

@simonbuehler
Copy link
Contributor Author

Thanks for the explanation,

  • apart from the ViewModels - what simple types do actually use the old cached values, i guess that most of the time new values are propagated to the JS side from c# Properties and the c# -> js conversion has to be done anyways?

  • wouldn't it be easier to change the key of the dictionary from object to wrapper<string propertyname, object value> or wrapper<datetime teimestamp, object value> ? This would allow to either update a entry or having a scheduler purging old entries every x seconds or when the memory size of the dictionary exceed a certain amount.

@simonbuehler
Copy link
Contributor Author

ok, this was quick an dirty: enabling cleanup with

public bool Release() => true; in internal abstract class JsBasicTyped<T>

yay!
can't seee any performance hit as the values do change on every update from c# anyway so no caching would speed this up!

@David-Desmaisons
Copy link
Member

Well, this Release method is where the reference counting should take place. Adding a count here should not have a big CPU impact.
I will investigate for sure.

@David-Desmaisons
Copy link
Member

Provided in release 1.7.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants