# Subject: Loading and unloading of shared libraries
Hi emscripten team,
I am currently experimenting with loading and unloading shared libraries during runtime, this means I want to compile C/C++ code to asm.js that loads and unloads shared libraries during runtime on demand.
The C++ code uses `libdl` to load the libraries into the memory (with `dlopen`), to initialize the libraries (with `dlsym`) and to unload the libraries (with `dlcose`).
This means I compile all the libraries to side modules (`-s SIDE_MODULE=1`) and the executable to a main module (`-s MAIN_MODULE`), which loads and unloads the other libaries.
My C/C++ code that loads and unloads libraries looks similar to:
```C++
// ...
// load shared library
void* moduleHandle = dlopen("path/to/someModule.lib", RTLD_NOW);
// initialize shared library
void* initSymbolHandle = dlsym(moduleHandle, "Initialize");
typedef shared_lib* (*initialize_function_type)();
initialize_function_type* initializeFunction = reinterpret_cast<initialize_function_type>(initSymbolHandle);
shared_lib sharedLibPointer = initializeFunction();
// use shared library
sharedLibPointer->use();
// ...
// de-initialize shared library
void* deInitSymbolHandle = dlsym(moduleHandle, "DeInitialize");
typedef void (*de_initialize_function_type)(shared_lib*);
deinitialize_function_type* deInitializeFunction = reinterpret_cast<de_initialize_function_type>(deInitSymbolHandle);
deInitializeFunction(sharedLibPointer);
// unload shared library
dlclose(moduleHandle);
```
My first question is:
1. Is the memory before loading the shared library identical to the memory after unloading of the shared library? This means is the shared completely completely cleaned from memory, including the symbols fetched during de-/initialization phases?
My concern is that the memory grows with each load and unload of a library and therefore the memory consumption grows during runtime.
I already experimented with this and also compiled to WebAssembly. I am currently planning to consider compiling to WebAssembly in the future. Therefore I would like to know:
2. Is there a significant difference in the implementation of WebAssembly regarding the un-/loading of shared libraries and the clean-up of the memory in comparison to the asm.js implementation?
During my WebAssembly experiments, I received the following error message using Chromium (for Firefox it worked):
```command line output
RangeError: WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.compile, or compile on a worker thread.
```
3. Is there an option to work around or fix this issue?
For my tests I used:
* emcc version 1.38.15
* Chromium Version 70.0.3538.102 (Official Build) Arch Linux (64-bit)
* Firefox version 63.0.2 (64-bit) for Arch Linux
My final question is:
Best regards,