vendredi 23 octobre 2015

Garbage collector reference (dependency) tracking when parameterized constructor invoked from reflection

I'm running into an issue where a reference (a dependency) injected in the constructor of an object is disposed while it should not.

Because this object is constructed by invoking a constructor by reflection, I suspect the garbage collector not tracking the link between the dependency and the object constructed.

Could there be an issue with garbage collected references and objects constructed by reflection ?

Here are more details about the scenario :
- A generic factory is creating an object from its given generic type (TSomeType)

  • To do so we retrieve the constructor via ConstructorInfo contructor = typeof(TSomeType).GetConstructor(typeof(SomeDependencyClass));
  • We then invoke constructor call with constructor.Invoke(new object[]{someDependencyInstance});
  • This instance is then returned by an IoC (ninject) in an ActionFilterAttribute on the OnActionExecuting method, where I store the reference in a class field for the OnActionExecuted method to use it.
  • When using it in the OnActionExecuted, someDependencyInstance has been disposed.

So my question is : could this be due to the fact that the references are not correctly tracked by the Garbage Collector when injecting it in an object by invoking its constructor by reflection ?





Aucun commentaire:

Enregistrer un commentaire