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 #15858 is a reply to message #15857] Mon, 12 May 2008 19:05 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
mrjt wrote on Mon, 12 May 2008 11:41

It is my understanding that the following code should execute without any memory leaks:
struct Item {
	String name;	
};

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

GUI_APP_MAIN
{
        // Example 1
	Array<Item> array;
	array.Create<Collection>().items.Add();

        // Example 2
	Collection *col = new Collection();
	col->items.Add();
	Item *item = (Item *)col;
	delete item;
}

But for some reason the destructor for 'items' isn't getting called. Adding a virtual destructor to force clearance just causes a crash in MemoryFreeDebug.

Is something broken or am I just missing something obvious?


Well, virtual destructor is absolutely required here.

The crash in MemoryFreeDebug... well, who knows, I would say it has another reason.

Mirek
 
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 02:45:26 CEST 2025

Total time taken to generate the page: 0.05718 seconds