feat: [Issue20] Add WeakReference to store reference types in a default provider #21
+176
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
#20
When storing a reference type variable as a dependency value created in the DefaultProvider, it was causing the assemblies to fail to unload within the Godot Editor every time a build was re-built. This only appears to happen in the case where a DefaultProvider is used, likely because a strong reference is created within the AutoInject framework instead of within the Godot game using the framework.
Within the AutoInject framework, this reference should be a WeakReference instead of a strong reference to allow the Godot game to manage the reference correctly and garbage collect it when appropriate.
Considerations
object
type create a performance issue?For these considerations, the best I understand is, previously storing value types within a
dynamic
causes them to be boxed and unboxed, which is the same as when storing them in anobject
type.As well, the WeakReference acts like a boxing and unboxing as well. I believe this means that there is no performance changes between this solution and the previous one.
Testing
To test this, create a simple class with a dependency on a
Godot.Resource
type with the previous version of AutoInject.Example:
Following these steps you should be able to see the error:
Following the same steps, with this branch, you should see no error.