Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » ~Link
~Link [message #38843] Wed, 23 January 2013 12:26 Go to next message
masu is currently offline  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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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 Go to previous message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Thanks, Mirek.
I was not aware of LinkOwner, but it is exactly what I need.

Matthias
Previous Topic: Repeatable crash
Next Topic: Is FrameLess() working under Linux ?
Goto Forum:
  


Current Time: Fri Mar 29 05:57:35 CET 2024

Total time taken to generate the page: 0.00974 seconds