title: Qt script destructor of own class is not called
body: <p>I am using qtscript4 and have added some types to the engine.</p>
  
  <p>I registered a function that creates a new object and registered it on the engine with passing ownership to the engine.
  But the object seems not to get destroyed then leaving scope (at least the debugger does not break at the destructor).</p>
  
  <p>following lines resemble the registration:</p>
  
  <pre><code>   QScriptEngine *io_en;
  
     qScriptRegisterMetaType_helper(io_en, metatypeid, marshalfunctions, demarshalfunction, QScriptValue());
     QScriptValue ctor = io_en-&gt;newFunction(ObjectConstruction&lt;T&gt;::constructMyObject);
     QScriptValue metaObject = io_en-&gt;newQMetaObject(&amp;QObject::staticMetaObject, ctor);
     io_en-&gt;globalObject().setProperty(name, metaObject);
  </code></pre>
  
  <p><code>ObjectConstruction&lt;T&gt;::constructMyObject</code> looks like the following:</p>
  
  <pre><code>template &lt;class T&gt;
  struct ObjectConstruction
  {
    static QScriptValue constructMyObject(QScriptContext *, QScriptEngine *engine)
    {
      T *ob = new T;
      return engine-&gt;newQObject(ob, QScriptEngine::ScriptOwnership);
    }
  };
  </code></pre>
  
  <p>The whole thing seems to work except the destruction. So I think the initial registration seems to be correct. Also the constructor gets called every time I have a <code>var c = new MyObj;</code> in the code but nothing happens if it goes out of scope.
  However the destructors get called at application exit. Maybe javascript has a different opinion of "goes out of scope". But my instantiations of the object are at function scope, so I expected them to be destroyed at the end of the function;</p>
  
  <pre><code>Main.prototype.someTest= function()
  {
    var c = new MyObj;
    c.doSomething();
  }
  </code></pre>
  
  <p>I hope somebody has any hints or suggestions. Thanks in advance.</p>