Is it still safe to delete nullptr in c++0x?

5.3.5/7 says: If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will call a deallocation function (3.7.4.2). Otherwise, it is unspecified whether the deallocation function will be called. And 3.7.4.2/3 says: The value of the first argument supplied to a deallocation function may be a null pointer … Read more

C++ Array of pointers: delete or delete []?

delete[] monsters; Is incorrect because monsters isn’t a pointer to a dynamically allocated array, it is an array of pointers. As a class member it will be destroyed automatically when the class instance is destroyed. Your other implementation is the correct one as the pointers in the array do point to dynamically allocated Monster objects. … Read more

Deleting a dynamically allocated 2D array

In reality, an array of pointers pointed to by a pointer is still an array of integral data types or numbers to hold the memory addresses. You should use delete[] for both. Also, yes, a new[] implies a delete[]. When you create an array of arrays, you’re actually creating an array of numbers that happen to hold the memory address for another array … Read more

C++ delete vector, objects, free memory

You can call clear, and that will destroy all the objects, but that will not free the memory. Looping through the individual elements will not help either (what action would you even propose to take on the objects?) What you can do is this: That will create an empty vector with no memory allocated and … Read more

Deleting array elements in JavaScript – delete vs splice

delete will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined: Note that it is not in fact set to the value undefined, rather the property is removed from the array, making it appear undefined. The Chrome dev tools make this distinction clear by printing empty when … Read more