If, after subsequent all People recommendations, you still have problems with RAM and CPU, then perhaps it’s simply because your application is really also hefty, plus a Raspberry Pi is not the right tool with the task. In this instance, you should check out alternate embedded board, for example Intel https://www.mirobot.ai/