hmemcpy / AgentMulder

** THIS PLUGIN IS NO LONGER MAINTAINED. PLEASE FOLLOW ERNICOMMUNITY FOR UPDATES **
https://github.com/ERNICommunity/AgentMulder
MIT License
151 stars 33 forks source link

Agent Mulder stops working if solution is closed, then re-opened #29

Closed hmemcpy closed 11 years ago

hmemcpy commented 12 years ago

"Leaked solution detected" is being thrown by ReSharper.

@citizenmatt, your help would be appreciated :)

citizenmatt commented 12 years ago

I can't reproduce this using master or develop. Any steps to repro?

citizenmatt commented 12 years ago

OK. Got it - I used a memory profiler. The problem is in the Ninject container's BindBasePattern. The code is checking to see if the current type implements Ninject's IBindingRoot interface, and to do so, it creates an instance of IDeclaredType and stores it in the class. The only problem is that the ComponentRegistration classes have the same lifetime as the shell, and the IDeclaredType instance has been created using an IPsiModule of the solution. This keeps the solution in scope, and so ReSharper complains.

When you re-open the solution (I bet it's a Ninject solution), the Ninject bindings are trying to match against a type representing IBindingRoot created with a different solution. I suspect that will fail.

You should be able to sort this by either not saving the created bindingRootType in a field, or by changing the call to IsDescendantOf to TypeElementUtil.GetAllSuperTypes and walk the returned list comparing fully qualified names. I haven't looked into the performance implications of either method...

hmemcpy commented 12 years ago

Matt, have I mentioned how awesome you are?!? :)

It was indeed in a Ninject solution where I encountered this! Also, you have hit the nail on the head - that's exactly where the problem is!

I have refactored the entire hack that checks for the IBindingRoot into a helper extension (StructureMap needs the same check, as both Ninject and StructureMap have Module-like classes, where the methods (For<>, Bind<>, etc) are members of the class, and not prefixed with an instance. SSR currently doesn't match implicit 'this', that's why I require that check.

I have already removed the static field, I will try to make the changes as you suggested!

Thanks again so very much!