Lesson 20 of 24
Pointers, new/delete மற்றும் Smart PointersPointers, new/delete and Smart Pointers
11 min 35 XP
new heap-ல் memory ஒதுக்கும், delete விடுவிக்கும். delete மறந்தால் memory leak. Modern C++-ல் unique_ptr / shared_ptr பயன்படுத்துங்கள்: அவை தானாக விடுவிக்கும்.
new allocates heap memory and delete frees it; forget the delete and you leak memory. Modern C++ uses unique_ptr and shared_ptr, which free memory automatically.
Example: edit me and press Run
Press Run to see the result here.new[] உடன் delete[]; new உடன் delete. கலந்தால் undefined behaviour. Smart pointers இந்தத் தவறுகளைத் தவிர்க்கும்.
Pair new[] with delete[] and new with delete; mixing them is undefined behaviour. Smart pointers avoid these mistakes entirely.