Is garbage collection automatic in standard C++?

前端 未结 8 2039
情深已故
情深已故 2020-12-08 23:12

From what I understand, in standard C++ whenever you use the new operator you must also use the delete operator at some point to prevent memory leaks. This is because there

8条回答
  •  Happy的楠姐
    2020-12-08 23:43

    Automatic garbage collection is useful, but you can still get memory leaks, as this question shows:

    Memory Leaks in C# WPF

    It is decreased in .NET and Java, but that doesn't mean it allows bad coding to be taken care of automatically.

    So, in C++ you need to explicitly release what you request, and I think that is sometimes better, as you are aware of what is going on. I wish in .NET and Java that the garbage collector did little in Debug mode, to help ensure people are aware of what they are doing.

提交回复
热议问题