Home » U++ Library support » U++ Core » ~Link
~Link [message #38843] |
Wed, 23 January 2013 12:26  |
masu
Messages: 378 Registered: February 2006
|
Senior Member |
|
|
Hi,
I made a little test with Link utility class and heap leaks have been detected when I use the following code:
struct LinkTest : Link<LinkTest> {
};
CONSOLE_APP_MAIN
{
LinkTest lt;
lt.InsertPrev();
lt.InsertNext();
lt.Dump();
}
This comes from the fact that the whole list is not destroyed when the destructor of lt is called at the end of the programm, but instead only lt is removed and the other heap allocated members in the list remain.
I propose to call DeleteList() in ~Link instead of calling UnLinkAll(). If one wants to unlink a single object obj within the list an obj.UnlinkAll() can be used.
It just does not feel the U++ way to me to have to call lt.DeleteList() at the end of the program.
Regards
Matthias
|
|
|
Re: ~Link [message #38863 is a reply to message #38843] |
Thu, 24 January 2013 19:52   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
masu wrote on Wed, 23 January 2013 06:26 | Hi,
I made a little test with Link utility class and heap leaks have been detected when I use the following code:
struct LinkTest : Link<LinkTest> {
};
CONSOLE_APP_MAIN
{
LinkTest lt;
lt.InsertPrev();
lt.InsertNext();
lt.Dump();
}
This comes from the fact that the whole list is not destroyed when the destructor of lt is called at the end of the programm, but instead only lt is removed and the other heap allocated members in the list remain.
I propose to call DeleteList() in ~Link instead of calling UnLinkAll(). If one wants to unlink a single object obj within the list an obj.UnlinkAll() can be used.
It just does not feel the U++ way to me to have to call lt.DeleteList() at the end of the program.
Regards
Matthias
|
Uhm, that would be very bad idea indeed.
Link is only just simple utility class used mostly in U++ libraries. It is not a container and in fact, 99% of uses are NOT allocating nodes on heap, but are linking nodes that exist independently (that is the original purpose of Link). E.g. see DisplayPopup. All that code would be broken - and we would need another class for the original purpose.
InsertAfter/InsertBefore are utility methods for very special uses. Anyway, if you really want to use Link the way you want, you can use LinkOwner.
Mirek
[Updated on: Thu, 24 January 2013 19:52] Report message to a moderator
|
|
|
Re: ~Link [message #38874 is a reply to message #38863] |
Thu, 24 January 2013 23:27  |
masu
Messages: 378 Registered: February 2006
|
Senior Member |
|
|
Thanks, Mirek.
I was not aware of LinkOwner, but it is exactly what I need.
Matthias
|
|
|
Goto Forum:
Current Time: Sun May 11 14:51:31 CEST 2025
Total time taken to generate the page: 0.00541 seconds
|