Re: Freeing memory used by QTableItem

Richard Dale <[email protected]>
Newsgroups gmane.comp.kde.devel.perl
Organization Lost Highway
Message-ID <[email protected]>
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.patch (text/x-diff, 1.2 KB)
--- Qt.xs.save	2004-07-09 04:29:16.000000000 +0100
+++ Qt.xs	2004-07-09 04:38:44.000000000 +0100
@@ -1746,6 +1746,44 @@
     if(!o) { XSRETURN_EMPTY; }
     QObject *qobj = (QObject*)o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject"));
     delete qobj;
+	
+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
 
 void
 mapObject(obj)
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.