+ 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

24th Apr 2019, 2:49 AM
Sonic
Sonic - avatar
9 Respostas
+ 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
24th Apr 2019, 3:08 AM
jay
jay - avatar
+ 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
24th Apr 2019, 10:14 AM
Darshan Rathod
Darshan Rathod - avatar
+ 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.
24th Apr 2019, 7:51 AM
Hare Shyam
Hare Shyam - avatar
+ 2
jay can you even count on the operating system reclaiming the memory?
24th Apr 2019, 10:11 AM
Jared Bird
Jared Bird - avatar
0
كيف الحال
24th Apr 2019, 7:53 PM
بنين العيدانية
0
مرحبا
25th Apr 2019, 10:25 PM
El-ghazouani Mohamed
El-ghazouani Mohamed - avatar
0
كيف حالكم
25th Apr 2019, 10:25 PM
El-ghazouani Mohamed
El-ghazouani Mohamed - avatar
- 1
مرحبا
24th Apr 2019, 7:53 PM
بنين العيدانية
- 1
hy
24th Apr 2019, 11:43 PM
Raùl Abdo
Raùl Abdo - avatar