Still reachable in valgrind

前端 未结 1 871
梦如初夏
梦如初夏 2021-01-18 06:30

While searching about still reachable in valgrind, some people say its not a problem. we don\'t nedd to fix it. Some people say it needs to be fixed.I would be better if som

相关标签:
1条回答
  • 2021-01-18 07:14

    It depends. "Still reachable" means you haven't deallocated a block of memory before exiting, but had a pointer to it.

    In a C++ program this means that some object could have not been deleted and therefore its destructor might not have been run and thus say some data might have not been saved onto disk for example and some other action might not have been taken and thus your program might produce unexpected behavior.

    However there're no destructors in C programs, so your program just can't depend on that. Also deallocating memory takes some time, so by not freeing memory on exit you can save some time - your program will exit faster (this can be significant for programs with lots of data).

    So IMO if your C program has "still reachable" blocks it's not a problem but this indicates that some code in the program doesn't free memory and so you can expect bugs when reusing that code.

    0 讨论(0)
提交回复
热议问题