0

I've some problems with deleting QSA's referred objects. In constructor, I've wrote:

  QSProject * project = {initialization of QSProject}
  MyWrapper * wrapper = new MyWrapper; // MyWrapper is QObject's child. It comes without parent here
  project->addObject(wrapper);

I've wrote in descructor:

  project->clearObjects();
  delete project;
  delete wrapper;

This code cause to segfault at destructor's execution, exactly -- when I'm trying to delete wrapper.

I've made some research and I know that:

  1. QSProject doesn't delete his "children objects", so this is not a "double delete" problem
  2. If I don't add wrapper to QSProject in constructor, it works well.
  3. If I don't delete wrapper in descructor, it works well (but memory leaks).

What's up?

Arenim
  • 4,097
  • 3
  • 21
  • 31
  • Just so you're aware, you know QSA has been deprecated and reached end-of-life in 2008? It has been replaced with [QtScript](http://doc.qt.nokia.com/latest/qtscript.html). It might not be applicable to your project, but I wanted to be sure you were aware. – Casey Apr 25 '11 at 16:33

1 Answers1

0

First, I'm not familiar with QSA, but given how the Qt API usually works QSProject is likely taking ownership of the object. This means QSProject is reparenting the object using QObject::setParent().

In which case you are doubly deleting the object.

Have you verified with a tool such as valgrind that you are in fact leaking memory when you omit the delete?

Casey
  • 6,166
  • 3
  • 35
  • 42
  • Yes. I've checked twice, that QSProject _don't_ take parentship on it's children and memory really leaks. – Arenim Apr 26 '11 at 09:21