+ 15
In the code below, if I comment out the "delete" line, the output from the destructor does not appear.
Does this mean that the destructor is invoked from outside the main function? https://code.sololearn.com/cnW3YEd76JMm/?ref=app
9 Answers
+ 14
No, as you called new without delete before the program ends the destructor is never called. The operating system simply reclaims that space in memory without knowing its contents.
So, moral of the story, always use delete or even better use smart pointers.
See:
https://en.cppreference.com/book/intro/smart_pointers
+ 3
You create an object by dynamic allocation with new in the SCOPE OF MAIN( )
function.
So you have to delete *t before MAIN( ) ends....
And when you delete *t,
first, it calls the destructor for your dynamically created object for TEST,
then it deletes t....
keep in mind,
....Use delete where you use new in the scope of an object ( before it ends ).
EXTRA THING :
Sometimes you need to call DESTRUCTOR explicitly. Refer below link....
https://www.youtube.com/watch?time_continue=1621&v=45uo_2It9dw
+ 2
Connection issues with Epson Printers are really very frequent for most of the devices. As it may not recognize in a proper manner. If they get an error like https://errorcode0x.com/fix-epson-printer-error-code-0x97/ that must be recovered by them.
+ 2
jay can you even count on the operating system reclaiming the memory?
0
كيف الحال
0
مرحبا
0
كيف حالكم
- 1
مرحبا
- 1
hy