Search code examples
c++memory-managementmemory-leaksdelete-operatorwt

How does Wt C++ call delete for allocated objects


When looking at any given Wt C++ example, there are a lot of new calls but how do these even get deleted? Also, are these even guaranteed to be deleted and if so, when/where?

EDIT: This link pretty much answered how it's probably also done in Wt, although it doesn't directly speak about Wt. Why does the use of 'new' cause memory leaks?


Solution

  • It is a little unsettling to see news without matching deletes..

    Wt takes ownership of Wt::Widget pointers that are added to a page or widget hierarchy. They are deleted automatically, as needed.

    Very soon Now, a new Wt 4.0 release will clarify this by requiring you to move std::unique_ptrs to these functions, so it is unambiguous that you are transferring ownership. Likewise, functions that remove widgets will return unique_ptrs to the calling code.