[Kde-perl] Freeing memory used by QTableItem

Oliver Kreuer okreuer at PSI.de
Fri Jul 9 13:22:35 CEST 2004


Hello,

thank you for your patch. With

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

this works fine. But I tried my example program (see attachment)
and I got the following error messages:

QGVector::remove: Index -2 out of range
QGVector::remove: Index -2 out of range
Memory fault

I also used Qt::debug qw(all) which printed:
...
...
In XS Autoload for Qt::TableItem::QTableItem()
Calling method  QTableItem* QTableItem::QTableItem(QTable*, 
QTableItem::EditType, const QString&)
with arguments (QTable, '0', '497')
In XS Autoload for Qt::TableItem::Never()
Calling method  static QTableItem::EditType QTableItem::Never()
with arguments ()
In XS Autoload for Qt::TableItem::QTableItem()
Calling method  QTableItem* QTableItem::QTableItem(QTable*, 
QTableItem::EditType, const QString&)
with arguments (QTable, '0', '498')
In XS Autoload for Qt::TableItem::Never()
Calling method  static QTableItem::EditType QTableItem::Never()
with arguments ()
In XS Autoload for Qt::TableItem::QTableItem()
Calling method  QTableItem* QTableItem::QTableItem(QTable*, 
QTableItem::EditType, const QString&)
with arguments (QTable, '0', '499')
0x8550e78->~QTableItem()
virtual 0x8524390->QTable::takeItem() called
In XS Autoload for Qt::Table::takeItem()
Calling method  void QTable::takeItem(QTableItem*)
with arguments (QTableItem)
virtual 0x8524390->QTable::cellGeometry() called
virtual 0x8524390->QTable::item() called
virtual 0x8524390->QTable::columnPos() called
virtual 0x8524390->QTable::rowPos() called
virtual 0x8524390->QTable::columnWidth() called
virtual 0x8524390->QTable::rowHeight() called
virtual 0x8524390->QTable::numRows() called
virtual 0x8524390->QTable::numCols() called
virtual 0x8524390->QTable::numCols() called
QGVector::remove: Index -2 out of range
In XS Autoload for Qt::TableItem::DESTROY()
In XS Autoload for Qt::TableItem::table()
Calling method  QTable* QTableItem::table() const
with arguments ()
Deleting (QTableItem*)0x8550e78
0x8550db8->~QTableItem()
virtual 0x8524390->QTable::takeItem() called
In XS Autoload for Qt::Table::takeItem()
Calling method  void QTable::takeItem(QTableItem*)
with arguments (QTableItem)
virtual 0x8524390->QTable::cellGeometry() called
virtual 0x8524390->QTable::item() called
virtual 0x8524390->QTable::columnPos() called
virtual 0x8524390->QTable::rowPos() called
virtual 0x8524390->QTable::columnWidth() called
virtual 0x8524390->QTable::rowHeight() called
virtual 0x8524390->QTable::numRows() called
virtual 0x8524390->QTable::numCols() called
virtual 0x8524390->QTable::numCols() called
QGVector::remove: Index -2 out of range
In XS Autoload for Qt::TableItem::DESTROY()
In XS Autoload for Qt::TableItem::table()
Calling method  QTable* QTableItem::table() const
with arguments ()
Deleting (QTableItem*)0x8550db8
0x85513b8->~QTableItem()
virtual 0x8524390->QTable::takeItem() called
Memory fault

Unfortunately I don't know what this means.

Oliver

Richard Dale wrote:
> 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
>>>Kde-perl at kde.org
>>>https://mail.kde.org/mailman/listinfo/kde-perl
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>--- 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);
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>Kde-perl mailing list
>>>Kde-perl at kde.org
>>>https://mail.kde.org/mailman/listinfo/kde-perl

-- 
Oliver Kreuer
PSI AG
Bernsaustrasse 4-6
42553 Velbert (Neviges)

Telefon +49/2053/919-211
Telefax +49/2053/919-194
E-Mail  okreuer at psi.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: table3.pl
Type: application/x-perl
Size: 5731 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-perl/attachments/20040709/743d8ee1/table3.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: table_example.one
Url: http://mail.kde.org/pipermail/kde-perl/attachments/20040709/743d8ee1/table_example.cc
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: table_example.two
Url: http://mail.kde.org/pipermail/kde-perl/attachments/20040709/743d8ee1/table_example-0001.cc


More information about the Kde-perl mailing list