Re: Freeing memory used by QTableItem

Richard Dale <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Organization Lost Highway
Message-ID <[email protected]>
Actually that patch doesn't work I'm afraid. Here's another one, but it still 
isn't right. This works:

my $junk = Qt::PushButton("Hello World!", undef);
Qt::dispose($junk);

But what I was really trying to do was this:

my $junk = Qt::PushButton("Hello World!", undef);
$junk->dispose();

I can't work out how to do that..

-- Richard


On Friday 09 July 2004 04:48, Richard Dale wrote:
> I recently had a similar problem with the qtruby bindings ( which are based
> on the perlqt code), and I solved it be adding 'dispose()' and
> 'isDisposed()' methods. Please find attach a patch for PerlQt 3.008 which
> adds the same methods.
>
> $ cp perlqtdispose.patch PerlQt-3.008/PerlQt
> $ cd PerlQt-3.008/PerlQt
> $ patch Qt.xs -p0 < perlqtdispose.patch
>
> Then make and install PerlQt..
>
> -- Richard
>
> On Monday 05 July 2004 14:51, Oliver Kreuer wrote:
> > Hello,
> >
> > how can I free memory used by an object of class Qt::TableItem myself?
> > I've read that takeItem only removes an item from an existing table
> > without destroying the Qt::TableItem object.
> > So since I can't simply say "delete <object>" in Perl I tried the
> > following:
> >
> > my @t = ();
> > for (my $i=0 ;$i<1000 ;$i++ )
> > {
> >       $t[$i] = Qt::TableItem(table,&Qt::TableItem::Never,"$i");
> > }
> >
> > sleep(10);
> >
> > for (my $i=0 ;$i<1000 ;$i++ )
> > {
> >     $t[$i] = "";
> > }
> >
> > But "top" shows me that memory usage after the last loop increases
> > instead of decreases.
> >
> > Thanks for your help,
> > Oliver
> >
> >
> > _______________________________________________
> > Kde-perl mailing list
> > [email protected]
> > https://mail.kde.org/mailman/listinfo/kde-perl

_______________________________________________
Kde-perl mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-perl
perlqtdispose_0.1.patch (text/x-diff, 1.5 KB)
--- Qt.xs.save	2004-07-09 04:29:16.000000000 +0100
+++ Qt.xs	2004-07-09 08:43:41.000000000 +0100
@@ -1388,6 +1388,7 @@
     QByteArray *s = (QByteArray*) tmp;
     delete s;
 
+
 # --------------- XSUBS for Qt::_internal::* helpers  ----------------
 
 
@@ -1746,7 +1747,7 @@
     if(!o) { XSRETURN_EMPTY; }
     QObject *qobj = (QObject*)o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject"));
     delete qobj;
-
+	
 void
 mapObject(obj)
     SV *obj
@@ -2119,6 +2120,44 @@
     OUTPUT:
     RETVAL
 
+void
+dispose(obj)
+    SV *obj
+    CODE:
+    smokeperl_object *o = sv_obj_info(obj);
+    if(!o || !o->ptr) { 
+		XSRETURN_EMPTY;
+	} else {
+		const char *className = o->smoke->classes[o->classId].className;
+		char *methodName = new char[strlen(className) + 2];
+		methodName[0] = '~';
+		strcpy(methodName + 1, className);
+		Smoke::Index nameId = o->smoke->idMethodName(methodName);
+		Smoke::Index meth = o->smoke->findMethod(o->classId, nameId);
+		if(meth > 0) {
+			Smoke::Method &m = o->smoke->methods[o->smoke->methodMaps[meth].method];
+			Smoke::ClassFn fn = o->smoke->classes[m.classId].classFn;
+			Smoke::StackItem i[1];
+			(*fn)(m.method, o->ptr, i);
+		}
+		delete[] methodName;
+		o->ptr = 0;
+		o->allocated = false;
+	}
+
+bool
+isDisposed(obj)
+    SV *obj
+    CODE:
+    smokeperl_object *o = sv_obj_info(obj);
+    if(!o || !o->ptr) { 
+		RETVAL = 0; 
+	} else {
+		RETVAL = 1;
+	}
+    OUTPUT:
+    RETVAL
+
 BOOT:
     init_qt_Smoke();
     qt_Smoke->binding = new QtSmokeBinding(qt_Smoke);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.