In MikTex, the memory size can be increased permanently increased by this way:
1, For Windows, Open a command Window and enter:
initexmf --edit-config-file=latex For Ubuntu, try this:
gedit .miktex/texmfs/config/miktex/config/latex.ini In the file opened (it may be empty), add:
main_memory=12000000
Save the file and quitequit. Then in the command window, enter:
initexmf --dump=latex
Then repeat the above steps for pdflatex (replace latex with pdflatex). If the error persists, try increasing the main-memorymain_memory value. For lualatex, the memory allocation is dynamic, hence the aforementioned steps are unnecessary, but if the compilation fails for lualatex, try for itthat as well.