Possible duplicate:Is it worth pointing to pointers to NULL in the destructor?
Does it make sense to point the pointer (which allocates heap memory) to NULLin the destructor?
NULL
class SampleClass { public: SampleClass( int Init = 0 ) { Value = new int( Init ); } ~SampleClass( void ) { delete Value; Value = NULL; // Is this pointless? } int *Value; };
Whereas regarding classes, when should I use the keyword explicit?
explicit
Yes. This is pointless because the object is in the process of destruction. Once it is destroyed, there will be no path to the pointer.
Yes, it makes no sense to point to the pointer at NULLthe very end of the destructor, since it will no longer exist as soon as you leave the destructor.
, .: -)
, MyClass int f(const MyClass&), f
MyClass
int
f(const MyClass&)
f
f(42)
f(MyClass(42))
, . .
NULL.
- SampleClass, ( ), , - , NULL ( , ).
Otherwise, you can continue to use the remote object and notice an error much later (when the memory is overwritten by another object). Such problems are often very difficult to debug.
This is not meaningless. Although it is true that, theoretically, the value will never be available again, setting it to NULL may help you in the future if any other fraud begins.
Source: https://habr.com/ru/post/1791841/More articles:CakePHP not loading model - cakephpAndroid ADB has moved and Eclipse is looking in the old place - androidНе удается получить ответ json с помощью $.getJSON - jsonDoes the Android browser have any error log file to debug the reasons for automatic shutdown? - androidone of the fields is count (*) NHibernate - nhibernateGetting ListView with FindControl - c #connecting characters * - c ++How can I use add_filter for a specific page template? - filterIs there a way to select MULTIPLE text areas with JS in Chrome and / or IE? - javascriptIs this setup / practice of web development suitable in the workplace? - language-agnosticAll Articles