|
|
Home » Community » Newbie corner » CTRL + C = 659 Heap leaks
|
Re: CTRL + C = 659 Heap leaks [message #52069 is a reply to message #52068] |
Mon, 15 July 2019 17:16   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Mon, 15 July 2019 02:17Novo wrote on Mon, 15 July 2019 06:15
This is not a correct behavior.
There is no correct behaviour. This is not defined anywhere in c++ standard.
Mirek
In this case this is a bug with U++. MemDiagCls shouldn't be a global object. It should be created on stack (by GUI_APP_MAIN or by CONSOLE_APP_MAIN). IMHO.
Regards,
Novo
|
|
|
|
Re: CTRL + C = 659 Heap leaks [message #52071 is a reply to message #52070] |
Mon, 15 July 2019 20:18   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Mon, 15 July 2019 13:35Novo wrote on Mon, 15 July 2019 17:16mirek wrote on Mon, 15 July 2019 02:17Novo wrote on Mon, 15 July 2019 06:15
This is not a correct behavior.
There is no correct behaviour. This is not defined anywhere in c++ standard.
Mirek
In this case this is a bug with U++. MemDiagCls shouldn't be a global object. It should be created on stack (by GUI_APP_MAIN or by CONSOLE_APP_MAIN). IMHO.
Then it would not work. Think about all that memory allocated in global objects... (and worse, not in initialization phase).
Instead of MemDiagCls you can put on stack a guard-object, which will detect that its destructor got called and set a flag on MemDiagCls.
IMHO, the problem is fixable ...
Regards,
Novo
|
|
|
Re: CTRL + C = 659 Heap leaks [message #52072 is a reply to message #52071] |
Tue, 16 July 2019 00:11   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Novo wrote on Mon, 15 July 2019 20:18mirek wrote on Mon, 15 July 2019 13:35Novo wrote on Mon, 15 July 2019 17:16mirek wrote on Mon, 15 July 2019 02:17Novo wrote on Mon, 15 July 2019 06:15
This is not a correct behavior.
There is no correct behaviour. This is not defined anywhere in c++ standard.
Mirek
In this case this is a bug with U++. MemDiagCls shouldn't be a global object. It should be created on stack (by GUI_APP_MAIN or by CONSOLE_APP_MAIN). IMHO.
Then it would not work. Think about all that memory allocated in global objects... (and worse, not in initialization phase).
Instead of MemDiagCls you can put on stack a guard-object, which will detect that its destructor got called and set a flag on MemDiagCls.
IMHO, the problem is fixable ...
Yeah, but then I will not catch leaks in global objects.
I could install Ctrl+C handler and do the same trick (disable leaks checker), but is it worth the effort?
Mirek
|
|
|
Re: CTRL + C = 659 Heap leaks [message #52073 is a reply to message #52072] |
Tue, 16 July 2019 02:11   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Mon, 15 July 2019 18:11
Yeah, but then I will not catch leaks in global objects.
I do not understand why. Just do not show memory leak report when an object on stack wasn't destroyed.
Regards,
Novo
|
|
|
|
Re: CTRL + C = 659 Heap leaks [message #52087 is a reply to message #52076] |
Wed, 17 July 2019 18:44   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Tue, 16 July 2019 03:38
Maybe we are nor speaking about the same thing...
What I mean is
struct MemDiagCls {
MemDiagCls();
~MemDiagCls();
static void ShowReport() { show = true; }
static bool IsShowReport() { return show; }
private:
static bool show;
};
bool MemDiagCls::show = false;
MemDiagCls::~MemDiagCls()
{
if(--sMemDiagInitCount == 0)
if (IsShowReport())
UPP::MemoryDumpLeaks();
}
struct LeakRepGuard {
~LeakRepGuard();
};
LeakRepGuard::~LeakRepGuard() {
MemDiagCls::ShowReport();
}
#define CONSOLE_APP_MAIN \
void ConsoleMainFn_(); \
\
int main(int argc, char *argv[]) { \
UPP::LeakRepGuard __; \
UPP::AppInit__(argc, (const char **)argv); \
UPP::AppExecute__(ConsoleMainFn_); \
UPP::AppExit__(); \
return UPP::GetExitCode(); \
} \
\
void ConsoleMainFn_()
A call to UPP::MemoryDumpLeaks() will be disabled if there was no stack unwinding. In all other cases it will work as before.
Leak report makes no sense when destructors of objects on stack were not called.
IMHO, this should be thread-safe because there is only one main() function ...
Regards,
Novo
|
|
|
|
|
Re: CTRL + C = 659 Heap leaks [message #52092 is a reply to message #52091] |
Wed, 17 July 2019 23:46   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Wed, 17 July 2019 17:04Novo wrote on Wed, 17 July 2019 18:44
Leak report makes no sense when destructors of objects on stack were not called.
This is debatable. It would warn you about calling "exit(0)" or equivalent, which is IMO good.
This leak report is very confusing. This thread is a proof of that.
You can do something like this instead ...
MemDiagCls::~MemDiagCls()
{
if(--sMemDiagInitCount == 0)
if (IsShowReport())
UPP::MemoryDumpLeaks();
else
UPP::Cerr() << "The World is going to end soon!" << UPP::EOL;
}
Regards,
Novo
|
|
|
|
Goto Forum:
Current Time: Tue May 13 11:13:02 CEST 2025
Total time taken to generate the page: 0.03377 seconds
|
|
|