简体   繁体   中英

How Can I Empty the Used Memory With Python?

I have just written a .psf file in Python for executing an optimization algorithm for Abaqus package, but after some analysis it stops. Could you please help me and write Python code to free the memory?

Thanks

You don't really explicitly free memory in Python. What you do is stop referencing it, and it gets freed automatically. Although del does this, it's very rare that you really need to use it in a well designed application.

So this is really a question of how not to use so much memory in Python. I'd say the main hint there is to try to refactor your program to use generators, so that you don't have to hold all the data in memory at once.

There are really only two python options. You can ask the garbage collector to please run. That may or may not do anything useful. Or you can delete a large container.

del my_var_name

If the memory is not really allocated by Python, you will need to use the interfaces of whatever module you are using to free it up.

by stopping using it when you do not need, python has garbage collector. Set the attributes, and variables to None when you are done with them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM