The server has 2GB of RAM memory. It takes up a lot of memory when I create or load a wallet. When I create about 50 wallets, the server is very slow because the memory is full. Is there a way to reduce the memory of a loaded wallet?
There is different way to optimize, configure or reduce the memory usage of bitcoind, I invite you to see this page from the bitcoind github who talk about it: https://github.com/bitcoin/bitcoin/blob/master/doc/reduce-memory.md
There is no way to reduce the amount of memory used by a loaded wallet other than modifying the code itself. There are no configuration options for this. You really should not be trying to run so many wallets on a low powered machine.