0

After I compile the .ui file in my qt project, I found that all pointers were newed in the constructor, but there is no place to delete them.

So how qt make sure there is no memery leak? Or I have to free them in the deconstructor?

Well, it's maybe a stupid question, but I don't know how to figure it out. If anyone can help me, I'll highly appreciate.

hehe HE
  • 21
  • 1
  • 1
    Qt has its own built-in memory management, see for example this other question: https://stackoverflow.com/questions/2491707/memory-management-in-qt For GUI elements, it basically makes sure that child items are deleted when the parent object gets destroyed – codeling Jan 20 '22 at 14:59
  • 2
    Qt uses a parent / child deletion model. When the parent is freed all of its children are freed. For a ui file I would expect uic to correctly setup the children so worrying about memory leaks due to the .ui file (and the header uic generates) should not be something you need to worry about. – drescherjm Jan 20 '22 at 14:59
  • Related: [https://stackoverflow.com/questions/19331396/how-does-qt-delete-objects-and-what-is-the-best-way-to-store-qobjects](https://stackoverflow.com/questions/19331396/how-does-qt-delete-objects-and-what-is-the-best-way-to-store-qobjects) – drescherjm Jan 20 '22 at 15:13
  • GCC/MS-VC have different ways of detecting memory leaks, but both support them natively. Alternatively and quicker, place a break point in the destructor of the class you think is being deleted. Again, how you do this is dependent on what environment you are using. – Tiger4Hire Jan 20 '22 at 15:16
  • Does this answer your question? [How does Qt delete objects ? And what is the best way to store QObjects?](https://stackoverflow.com/questions/19331396/how-does-qt-delete-objects-and-what-is-the-best-way-to-store-qobjects) – TrebledJ Jan 30 '22 at 17:40

0 Answers0