2

I understand how to load an F# dll into a project. But I would like to be able to load specific parts of them dynamically and without a big performance hit from the dll being purely functional.

Jesse Glover
  • 325
  • 3
  • 14
  • why do you want to unload the DLL. It is unlikely to do anything if you are not using its functions – John Palmer May 06 '16 at 01:12
  • Two reasons. First reason: Is to expand my knowledge with a new concept, even if it wouldn't be used often. Second reason: My mentor mentioned to me that since the project I am working will be purely functional, all of the resources will be loaded into memory and could cause a performance hit for critical tasks. – Jesse Glover May 06 '16 at 01:28
  • Well, if you really need the memory the dll will just get put in the pagefile/swap, so perf is almost certainly irrelevant. – John Palmer May 06 '16 at 01:29
  • 2
    While I understand the words, I don't understand the intent here. You seem to be working with some strange preconception. There's nothing *inherent* about F# or functional code that would make it hog resources in a way a C# or OO code couldn't. You're solving the wrong problem here. – scrwtp May 06 '16 at 07:40
  • The statement "since the project [...] will be purely functional, all resources will be loaded into memory" hints at strong prejudices, combined with a grave lack of knowledge. F# compiles into a perfectly normal .NET library, and gets loaded just as a C# DLL would. And whether your functional code is performant or not is a question of your skills, rather than the language - mind you that you can write functional code just as well in C#. – Anton Schwaighofer May 06 '16 at 08:52
  • 2
    `My mentor mentioned to me that since the project I am working will be purely functional, all of the resources will be loaded into memory and could cause a performance hit for critical tasks.` Over the many years I have come to learn that if someone gives you advise and you did not know it already or understand it with enough clarity to explain to another, then do not take it for face value, but test it and verify it so that you learn from your own experience rather than what was given to you. You may find that what you thought you heard and understood is no the same what was meant. – Guy Coder May 06 '16 at 12:30
  • I really do appreciate all of your comments on this post and will take all of the advise you folks have given me and apply it. – Jesse Glover May 06 '16 at 22:41

1 Answers1

4

To unload an application domain

There is no way to unload an individual assembly without unloading all of the application domains that contain it. Use the Unload method from AppDomain to unload the application domains. For more information, see How to: Unload an Application Domain.

Taken from https://msdn.microsoft.com/en-us/library/ms173101.aspx

The idea will be to initialize a new application domain for the F# library, then drop it after you're done using it. I think you're going to have to make sure you compile the F# lib as a Strong-Named assembly and add it to the GAC to accomplish this, but I'm not positive.

Community
  • 1
  • 1
Jonathon Chase
  • 9,396
  • 21
  • 39
  • With that in mind, I guess if I were to go the route of dynamically loading and unloading an assembly; I would have to split the project into many different assemblies in order to accomplish this sort of idea. Thank you for your answer. – Jesse Glover May 06 '16 at 01:44