What potential memory leaks will not have a hidden descriptor? I know that if you have anything stored on the heap, it will not process it, and if you have a connection to a file or database, this must be handled manually. Is there anything else? Like, say, non-basic data types like vectors?
Also, in an explicit destructor, do you need to destroy heapless variables that would be destroyed implicitly or would they be processed automatically?
thank
, . , , - , , .
; , . , . , : int, float, double, short, bool .., .
int, float, double, short, bool
, , ?
, , .
:
, , , , , .
, , RAII ( - ). , , , , , . , , . boost:: shared_ptr. (btw, , ++, ...)
.. , .
-, ( - ), .. , , . , , . RAII :)
, . , : , .
, , - .
, " " - , . , .
, " " FILE *, , FILE * - C-, . FILE * . " " std::ofstream, , .
std::ofstream
, . , .
-, , , , . , .
- , . , , , , .
, ++, , , , . : , , , , , -:). , - - -. , , , . shared_ptr .
shared_ptr
" "
++ "" " ". , , , , , , "".
. , t t .
t
class T { A a; B b; C c; // ... } t;
t : ~T(), ~C(), ~B(), ~A(). . . , , ~T() .
~T()
~C()
~B()
~A()
. , 1, ~C(), ~B() ~A() - .
, C, . , ( ) , - C - ~T(), C , , , ~T().
, .
-.
, . , , , .
, , -.
- , , auto_ptrs, , std- ++, . , , ++, , .
STL , - .
. , , std::auto_ptr<Data>, dtor . . , implict dtor, dtor, dtors .
std::auto_ptr<Data>
Now a good class class contains all the important resources as members with corresponding dtors. As a result, the dtor body does not have to do anything to prevent resource leakage. Of course, there is one exception to this rule: the resource management classes themselves manage exactly one resource and, therefore, clear this one resource from its dtor.
Source: https://habr.com/ru/post/1745422/More articles:How to use magnification controls in TextView in Android? - androidHow to change the default MySql sort for rake db: create: all in rails? - mysqlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1745419/add-objects-to-association-in-onpreinsert-onpreupdate&usg=ALkJrhiMR4JLM-hKwnBcuSj5QZZHAZAxPwCan I use Swallow SocketExceptions in some situations? - c #как написать адрес (указатель) в текстовом файле, который можно прочитать и разыменовать в C - cASP.NET How to use WebConfigurationManager to get a section from a Specific configuration file? - asp.netRoyal Mail PAF UK Account Address via Zip Code Alternatives? - postal-codeImage resizing: poor quality jpeg and black PNG backgrounds - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1745426/idn-aware-tools-to-encodedecode-human-readable-iri-tofrom-valid-uri&usg=ALkJrhhVE6X_9QvrsWLTbGj2igzAyqkpawMysterious logging.basicConfig problem (Python) - pythonAll Articles