In the integer section of the GMP manual:
Function: void mpz_clear (mpz_t x)
Free the space occupied by x. Call this function for all mpz_t variables when you are done with them.
Calling this procedure slows down my program, so I'd prefer not to do it if it's unnecessary.
Question: What happens if I don't use mpz_clear?
My guess would be that memory leakage could occur. Although, I'm unsure about whether or not I should be concerned about this (e.g. C might clean it up for me, or perhaps the memory is returned when the program exits).
It will cause you a memory leak.
C does not have a garbage collector to free it for you. You have to do so by calling the said function.
Yes, the memory is reclaimed by the OS when the program exits. But if you keep keep on leaking memory through continuous allocation and no deallocation then probably your program will not run properly for longer times because it wouldn't have enough memory due to continuous memory leakage.
If calling the function gives you a crash, You should debug and find the reason for crash and fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With