JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
572 stars 119 forks source link

Automatic Cleanup of generated Assembly #131

Closed Angr1st closed 5 years ago

Angr1st commented 5 years ago

Hello ,

I am trying lamar to generate n implementations of an interface at runtime. Will these generated assemblys be disposed eventually when there is no reference to it's types or will they never disappear? Would I need to unload them manually?

jeremydmiller commented 5 years ago

You can't unload an assembly in .Net to the best of my knowledge.

Angr1st commented 5 years ago

I think with AppDomains in .net it is indeed possible to unload assemblys If they are in a seperate AppDomain. Dotnet Core 3.0 will also have the ability to unload assemblys. They are already testing that. Hopefully someone will create a library in the Future creating a unified way on all plattforms to unload assemblys.

Jeremy D. Miller notifications@github.com schrieb am Fr., 15. März 2019, 21:05:

You can't unload an assembly in .Net to the best of my knowledge.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JasperFx/lamar/issues/131#issuecomment-473423816, or mute the thread https://github.com/notifications/unsubscribe-auth/ARjQ_dnW6OpqDSAcGcYFymN33tcInGCmks5vW_zsgaJpZM4bV2Jt .

jeremydmiller commented 5 years ago

You cannot use an AppDomain to unload an Assembly. It's possible that you could with the AssemblyLoadContext stuff in Core. Either way, you can't unload an assembly when you're still using a Type from that assembly

Angr1st commented 5 years ago

The generated Assembly would need to be loaded inside a separate AppDomain. You would have to dispose of all instances of the created type before unloading the Assembly by unloading the AppDomain.

Jeremy D. Miller notifications@github.com schrieb am Mo., 18. März 2019, 11:57:

You cannot use an AppDomain to unload an Assembly. It's possible that you could with the AssemblyLoadContext stuff in Core. Either way, you can't unload an assembly when you're still using a Type from that assembly

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JasperFx/lamar/issues/131#issuecomment-473863342, or mute the thread https://github.com/notifications/unsubscribe-auth/ARjQ_SaPXm_acqsIf35y5NX1O4o6thhQks5vX3EEgaJpZM4bV2Jt .

jeremydmiller commented 5 years ago

@Angr1st That doesn't help at all. If you're generating a dynamic type, it's because you need it later.

Angr1st commented 5 years ago

But If I have an Infinite Number of Types that I want to generate during the runtime of the service but I only need a limited number of them at a time. It would be nice to be able to unload the types I dont need and recreate when needed. For better performance I would chache a number of them to not have to recreate them everytime.

Jeremy D. Miller notifications@github.com schrieb am Mo., 18. März 2019, 12:47:

@Angr1st https://github.com/Angr1st That doesn't help at all. If you're generating a dynamic type, it's because you need it later.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/JasperFx/lamar/issues/131#issuecomment-473877853, or mute the thread https://github.com/notifications/unsubscribe-auth/ARjQ_T7NIrTyiNHrL7emKY0hX4iThOqCks5vX3zLgaJpZM4bV2Jt .

jeremydmiller commented 5 years ago

The compilation doesn't apply to singleton scoped objects and their immediate dependencies, if that helps