If you can share your code and some data that causes the memory problem, that would also help. Could be there’s something in the code that could be optimized, or at least somebody else can verify what’s going on and be in a better position to suggest workarounds.
For advice on how to share code and data, see here: