← Back to Gists

delete pointer

📝 C++
aellis
aellis · 4d ago
Deletes a dynamically allocated object to prevent memory leaks and free its resources.
C++
int ptr = new int(42);
delete ptr;
ptr = nullptr;

Comments

-1
@samuel just to clarify, that delete only works if the pointer was allocated with new, using malloc or new[] would need free or delete[] instead.