Window leaks when closed

9 views
Skip to first unread message

Stefan Monov

unread,
Feb 4, 2011, 11:23:10 AM2/4/11
to qt4d...@googlegroups.com
Hi.
In my game I'm getting some leaks due to qt4dotnet. I isolated it to
the following code. To test it, open Task Manager in Windows, look at
the memory usage graphs, run the test app, and you'll see that
everytime you press a key in the test window, the memory usage of the
app increases when it should stay the same. I think qt4dotnet is
internally keeping a handle to the closed window in some list and
isn't removing it from the list, so it doesn't get collected. Any
thoughts?

------------
using System;
using com.trolltech.qt.gui;

class Test : QWidget
{
const int w = 1000 * 1000 * 10;
public byte[][] Data = new byte[w][];

public Test()
{
for (int x = 0; x < w; x++)
{
Data[x] = new byte[1];
}
show();
GC.Collect(); // so measurements are more accurate
}

protected override void keyPressEvent(QKeyEvent arg__1)
{
disposeLater();
new Test();
}

[STAThread]
static void Main(string[] args)
{
QApplication.initialize(args);

new Test();

QApplication.exec();
}
}
------------

Frank T. Bergmann

unread,
Feb 23, 2011, 12:01:09 PM2/23/11
to qt4d...@googlegroups.com
Hello Stefan,

Sorry you are experiencing trouble. I tried to reproduce the issue you
described but could not. Just so we are sure we are on the same page, I
compiled the program like this:

"\Windows\Microsoft.NET\Framework\v3.5\csc.exe" test.cs -r:qtjambi-4.5.2
_01.dll -r:IKVM.OpenJDK.Core.dll /platform:x86

And ran it with test.exe

Immediately the window starts and is closed, no hitting of any keys is doing
anything. When I remove your gc collect and disposeLater calls I get new
windows but of course after some time I get an out of memory exception:

QtJambi: Exception pending in native code in file
'..\cpp\com_trolltech_qt_gui\qtjambishell_QWidget.cpp':746
java.lang.OutOfMemoryError
at cli.Test.<init>(Unknown Source)
at cli.Test.keyPressEvent(Unknown Source)
at IKVM.Runtime.JNIEnv.InvokeHelper(Unknown Source)
at IKVM.Runtime.JNIEnv.CallVoidMethodA(Unknown Source)
at com.trolltech.qt.gui.QApplication.exec(Native Method)
at cli.Test.Main(Unknown Source)

What I'm wondering is what are you doing differently ... when are you
hitting the keys? What version of qt4dotnet / qtjambi are you using?

Best
Frank

> --
> You received this message because you are subscribed to the Google
> Groups "qt4dotnet" group.
> To post to this group, send email to qt4d...@googlegroups.com.
> To unsubscribe from this group, send email to
> qt4dotnet+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/qt4dotnet?hl=en.

test.cs

Stefan Monov

unread,
Feb 23, 2011, 2:44:12 PM2/23/11
to qt4d...@googlegroups.com
Hi Frank.
First off, the Jambi DLL I'm referencing is qtjambi-4.6.3.dll (from
the latest qt4dotnet release) and not qtjambi-4.5.2_01.dll (from the
previous release).

With your command line (except with the 4.6.3 Jambi DLL), I get the
same thing as you - immediately the window appears and is closed.
However, my original command line was different. The relevant
difference was that mine had a /debug+ at the end:


"\Windows\Microsoft.NET\Framework\v3.5\csc.exe" test.cs

-r:qtjambi-4.6.3.dll -r:IKVM.OpenJDK.Core.dll /platform:x86 /debug+
And when compiled with /debug+, I get the behavior I described in the
original mail.
So if you compile with /debug+, you'll probably be able to reproduce the leak.

Also, after sending my first mail, I was able to narrow down the
problem to Qt Jambi itself, by porting my testcase to Java. So it's
not actually related to qt4dotnet. I've contacted the Qt Jambi dev and
he's looked at the problem but has been unable to solve it so far.
I've filled two bugreports about it:
http://redmine.smar.fi/issues/134
http://redmine.smar.fi/issues/135
One of them is about the leak, and the other is about a crash I was
getting, which is almost certainly the same crash you are getting.

The crash is pretty random, in that any small change in the test code,
or in the build config, can trigger it or hide it. That's probably the
reason it's triggered by a lack of /debug+.

Stefan Monov

unread,
Feb 23, 2011, 2:51:57 PM2/23/11
to qt4d...@googlegroups.com
(Oh, I forgot to mention that the "window immediately starts and is
closed" behavior you're seeing is, in fact, caused by a silent crash.
Which is probably the same crash as the one I've posted at the Qt
Jambi bug tracker.)

Stefan Monov

unread,
Feb 23, 2011, 3:01:12 PM2/23/11
to qt4d...@googlegroups.com
I'm attaching the chat we had with the Qt Jambi dev, in case you feel
like reading.
log.txt
Reply all
Reply to author
Forward
0 new messages