Install more RAM is your best approach, if possible/practical,
or stop running stuff (that is, optimize your Operating System)
Recording isn't the issue - it has EVERYTHING to do with what is running.
There is no real 'easy button' for fixing out of RAM, especially when starting with such a small amount (by modern standards). There are lots of possibilities, with much of it being 'it depends' type answers/guidance. sorry not something I'm going to get into on a support forum like this. (it is something I do for family and friends, and get paid a small fortune for IT consulting)
Hopefully you know someone computer knowledgeable who can help you.
Your situation is that you are asking more of your computer than it is configured and capable of. Your short options are
- upgrade or replace the computer to be more powerful/capable
- lower your demands on the computer (and be aware that optimization may or may not get you far enough, hence I'd be cautious about paying any real amount of money to someone to do this for you.)
Sorry, maybe someone else can tell you if Win10, your game and OBS in 4GB of RAM will ever work adequately