-
Notifications
You must be signed in to change notification settings - Fork 235
WeakReference garbage collection #604
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,8 @@ public class WeakCollection<T> : IEnumerable<T> where T : class | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public void Add(T value) | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| // Need a way to reset _firstAvailableIndex periodically | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for (var index = _firstAvailableIndex; index < _store.Count; index++) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
14
to
18
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this spot is the main source of constant growth of GC Handlers and WeakReferences. I don't have a good idea about how to fix it and I'd appreciate some guidance. This issue can only be observed if a static method Every time when a template is compiled, new instances of Handlebars.Net/source/Handlebars/HandlebarsEnvironment.cs Lines 132 to 133 in 9cf1672
Those new instances are then subscribed to the original FormatterProvider and ObjectDescriptorFactory objects from the main configuration object. WeakCollection has a mechanism to detect dead references and re-use WeakReference objects to store new values. It's done by resetting
Handlebars.Net/source/Handlebars/Collections/ObservableIndex.cs Lines 34 to 52 in 9cf1672
But none of the methods that call So maybe the fix should be to keep track of disposable containers in the methods that call |
||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| if (_store[index] == null) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -46,6 +46,8 @@ internal struct BindingContextPolicy : IInternalObjectPoolPolicy<BindingContext> | |||
|
|
||||
| public bool Return(BindingContext item) | ||||
| { | ||||
| item.Configuration = null; | ||||
|
|
||||
| item.Root = null; | ||||
|
Comment on lines
47
to
51
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But it makes sense to clear Configuration property when returning BindingContext to the pool because this property will be set to a new value in the
|
||||
| item.Value = null; | ||||
| item.ParentContext = null; | ||||
|
|
||||



Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddOrReplace()method always adds a key-value pair even if the key was found and replaced in the dictionary. This issue can be observed by inspecting the configuration object of Handlebars with a shared environment (Handlebars.CreateSharedEnvironment(configuration)) after multiple compilations.