Is there an acceptable limit for memory leaks?

前端 未结 11 2205
無奈伤痛
無奈伤痛 2021-02-02 12:08

I\'ve just started experimenting with SDL in C++, and I thought checking for memory leaks regularly may be a good habit to form early on.

With this in mind, I\'ve been

相关标签:
11条回答
  • 2021-02-02 12:32

    It depends on your application. Some leaking may be unavoidable (due to the time needed to find the leak v.s. deadlines). As long as your application can run as long as you want, and not take an crazy amount of memory in that time it's probably fine.

    0 讨论(0)
  • 2021-02-02 12:34

    For a desktop application, small memory leaks are not a real problem. For services (servers) no memory leaks are acceptable.

    0 讨论(0)
  • 2021-02-02 12:38

    As per Rob Wells' comments on Purify, download and try out some of the other tools out there. I use BoundsChecker and AQTime, and have seen different false positives in both over the years. Note that the memory leak might also be in a third party component, which you may want to exclude from your analysis. From example, MFC had a number of memory leaks in the first view versions.

    IMO, memory leaks should be tracked down for any code that is going into a code base that may have a long life. If you can't track them down, at least make a note that they exist for the next user of the same code.

    0 讨论(0)
  • 2021-02-02 12:40

    Living with memory leaks (and other careless issues) is, at its best, (in my opinion) very bad programming. At its worst it makes software unusable.

    You should avoid introducing them in the first place and run the tools you and others have mentioned to try to detect them.

    Avoid sloppy programming - there are enough bad programmers out there already - the world doesn't need another one.

    EDIT

    I agree - many tools can provide false positives.

    0 讨论(0)
  • 2021-02-02 12:43

    Most OSes (including Windows) will give back all of a program's allocated memory when the program is unloaded. This includes any memory which the program itself may have lost track of.

    Given that, my usual theory is that it's perfectly fine to leak memory during startup, but not OK to do it during runtime.

    So really the question isn't if you are leaking any memory, it is if you are continually leaking it during your program's runtime. If you use your program for a while, and no matter what you do it stays at 120 bytes lost rather than increasing, I'd say you have done great. Move on.

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