Unmanaged C ++ garbage collection help

I am a .net programmer, without much experience with unmanaged code. I am adding changes and additions to an unmanaged project, and everything works fine. Can you give me some guidance as to which code / objects I need to worry about garbage collection?

TIA

+3
source share
6 answers

Missing. C ++ has no garbage collector.

+9
source

In C ++, when allocating memory manually using an operator, newspecifying it frees this memory later (when it is no longer needed) using the operator delete.

/ malloc/?

+7

, , .

, , (new/malloc/createobject/globalalloc/sysstring/...)

MSVC (COM) ATL "RAII",
CComPtr<>
CComQIPtr<> , .

++ std::auto_ptr<>, boost/tr1 / ptr - , [], []

+3

COM. , AddRef() Release(), COM-, . COM .NET.

delete, .

+2

karlphillip .

, , .

, -, .

, , .

,

delete foo;
foo=null;

the next time you can check if it is zero, and otherwise delete them. And the best ... even if you try to remove the null pointer, nothing will happen! :)

+2
source

Find out if the code uses smart pointers (probably this is the case), smart pointers must destroy the objects themselves when they go out of scope.

0
source

Source: https://habr.com/ru/post/1761957/


All Articles