Good practices for memory gestion
-
Hello everybody out there!
There are several benchmarks analysing efficiency of different languages, tackling with very specific topics – loops, conditional branching, etc., – but I need a more general overview. Hence, I am creating a benchmark with a more general application and using a development framework.
You guessed it, I have chosen Qt as the testing framework. I plan in creating the same application in several languages, being C++, Python, and Rust, as well as two versions mixing C++ with Python and Rust with Python. For now on, I have created the C++ and Python version :
https://framagit.org/python-with-framework-benchmarking/pure-python
https://framagit.org/python-with-framework-benchmarking/pure-cppHere is the trouble: in the C++ version, memory liberation is slower than the Python version. I think I am doing something wrong, but I do not know what should be done. I try and make memory handling as safe, standard and automatic as possible, but I think there is something I did not understand in Qt memory handling.
I am sorry, I cannot make a specific example, as I do not know what I am missing. Still, I have tried to document the code as much as possible and make it as readable as possible. If somebody can have a look and make me some advice, I guess it will be helpful.
Best regards.
-
Hi,
Without having dived in your source code, I think one key difference to take into account: Python is garbage collected while C++ is not.
Also, deleting an object in C++ does not mean that the memory is immediately released to the OS. It may happen at different times depending on your application memory usage pattern, OS etc.