Trolltech Home | QSA-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

QSA-interest Archive, May 2006
QObject wrappers in QSA "garbage collection"


Message 1 in thread

Is there any way to do some "garbage collection" in QSA?

I have created QObject Wrappers for my classes, like this:

class QWrapper1: public QObject {
 ...
public:
 QWrapper1(boost::shared_ptr<Something> theObject,...) {
  obj=theObject;
  ...
 }
 ...
public slots:
 QWrapper1* getChild(const QString &name) {
  return new QWrapper1(obj->getChild(name),...);
 }
 ...

private:
 boost::shared_ptr<Something> obj;
}

I have observed, that QSA does not deallocate such returned objects once they are not used anymore,
like in this QSA example:

var x=QWrapper1Instance.getChild("a child");
x=something_else;
//whatever was allocated in QWrapper1::getChild is now lost

Is there any way to do it properly? I.e. deallocate the wrapper once QSA is finished using it?
Or I am doing something wrong and it should be done somehow else?

I looked at QSWrapperFactory, but there is a problem that in most my classes the nonQObjects
are instances of boost::shared_ptr<Something> and they can't be converted to void*
(the & operator is redefined for shared pointer to return address of the pointer within,
 not shared_ptr itself)
So I can't use the QSWrapperFactory.

Any ideas how to solve it optimally?

Martin Petricek

To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx


Message 2 in thread

tux@xxxxxxxxxx wrote:
> Is there any way to do some "garbage collection" in QSA?
> 
> I have created QObject Wrappers for my classes, like this:
> 
> class QWrapper1: public QObject {
>  ...
> public:
>  QWrapper1(boost::shared_ptr<Something> theObject,...) {
>   obj=theObject;
>   ...
>  }
>  ...
> public slots:
>  QWrapper1* getChild(const QString &name) {
>   return new QWrapper1(obj->getChild(name),...);
>  }
>  ...
> 
> private:
>  boost::shared_ptr<Something> obj;
> }
> 
> I have observed, that QSA does not deallocate such returned objects once they are not used anymore,
> like in this QSA example:

QSA cannot take ownership of arbitrary objects that gets passed into the 
runtime through slots, so these objects will not be deleted. You will 
have to manage those yourself. Objects created through QSObjectFactory 
or QSWrapperFactory and all internal objects are memory managed by QSA 
automatically.

If the return type of your slot was some non QObject pointer type rather 
than QWrapper1 you could install a wrapper factory for that pointer type 
   and have the wrapper object memory manage the pointer.

-
Gunnar

To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx