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 » Heap-leaks and polymorphic containers
Re: Heap-leaks and polymorphic containers [message #15864 is a reply to message #15858] Tue, 13 May 2008 15:46 Go to previous messageGo to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
luzr wrote on Mon, 12 May 2008 18:05

Well, virtual destructor is absolutely required here.
Hmm. I understand why this works (the implicit destructor isn't virtual):
struct Item : public Moveable<Item> {
	String name;
	
	virtual ~Item() { }	
};

struct Collection : public Item
{
	Array<Item> items;
};

GUI_APP_MAIN
{
	Collection *col = new Collection();
	col->items.Add();
	Item *item = (Item *)col;
	delete item;
}

But what baffles me is why this works with Vector, but not Array (the Array's destructor doesn't get called but the Vector one does).
struct Item : public Moveable<Item> {
	String name;	
};

struct Collection : public Item
{
	Vector<Item> items; // Heap leak if changed to Array
};

GUI_APP_MAIN
{
	Collection *col = new Collection();
	col->items.Add();
	Item *item = (Item *)col;
	delete item;
}
Confused

[Updated on: Tue, 13 May 2008 15:59]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Using NTL outside of U++?
Next Topic: System() call
Goto Forum:
  


Current Time: Fri Aug 22 01:58:34 CEST 2025

Total time taken to generate the page: 0.10111 seconds