Is there an acceptable limit for memory leaks?

前端 未结 11 2381
無奈伤痛
無奈伤痛 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条回答
  •  萌比男神i
    2021-02-02 12:22

    If you are really worried about memory leaking, you will need to do some calculations.

    You need to test your application for like, an hour and then calculate the leaked memory. This way, you get a leaked memory bytes/minute value.

    Now, you will need to estimate the average length of the session of your program. For example, for notepad.exe, 15 minutes sounds like a good estimation for me.

    If (average session length)*(leaked bytes / minute) > 0.3 * (memory space normally occupied by your process), then you should probably do some more efforts to reduce memory leaks. I just made up 0.3, use common sense to determine your acceptable threshold.

    Remember that an important aspect of being a programmer is being a Software Engineer, and very often Engineering is about choosing the least worst option from two or more bad options. Maths always comes handy when you need to measure how bad an option is actually.

提交回复
热议问题