Home » U++ Library support » TopWindow&PopUp, TrayIcon » TopWindow when Close override show exception unduly
Re: TopWindow when Close override show exception unduly [message #56182 is a reply to message #56181] |
Thu, 04 February 2021 16:21   |
Oblivion
Messages: 1226 Registered: August 2007
|
Senior Contributor |
|
|
Hello BetoValle,
void Close() override {
delete this; // error show heap is corrupted !!!!
}
I don't think there is any bug in U++. You are trying to delete an object within the same object. That call to TopWindow::Close() will return to its caller, which is the TopWindow itself, and it will be a freed memory address. So you get heap corruption. Never do that. 
Not to mention the SMain instance (se) is allocated on stack. You don't need to delete it anyway.
TopWindow::Close() method is useful for cleaning up your code, if required. It is not where you delete a window. In fact, unless it is absolutely necessary, we avoid using 'delete' in U++.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Thu, 04 February 2021 16:34] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Aug 23 07:18:08 CEST 2025
Total time taken to generate the page: 0.04992 seconds
|