If you think you might run into memory problems, it is a good idea to write the draws out to a CSV file as they go. This is done via the sample_file argument to sampling and stan in RStan and PyStan. However, there is a good chance you will run out of RAM reading those draws back into an interactive session. Often in situations like this, people are defining things in transformed parameters that they do not really need to store draws of and would be better off defining them in the model block. Or they are defining a bunch of stuff in the generated quantities block that would be better off with a standalone generated quantities file. Or they are not making use of the pars and include arguments for things they they are not interested in making inferences about beyond perhaps glancing at the posterior means.