QDebug() prevents from crash?
-
wrote on 15 Apr 2011, 12:32 last edited by
Hello,
I´ve got a strange problem -at least for me :D
My program crashes and when I insert a @qDegug() << "foo";@ ,it runs.
Unfortunately, I was not able to write a minimum example, that compiles and shows the same problem.
So just here a few lines from my code, to make you understand my problem:@
for (int i = 0; i < knownPivotFeatures.size(); i++) {
// qDebug() << "foo";
if(knownPivotFeatures[i]){
qDeleteAll(knownPivotFeatures[i]);
} else {
QDEBUG<<"Hashmap does not exist";
}
}
@
where knownPivotFeatures is a QList<QHash<QUuid, MyClass const>*>.(Another issue is, that the compiler seems to change the order. I added another qDebug() << "bar"; to the Destructor of MyClass. And first, the "foo"s (more than one ;)) are printed and finally the "bar"s.)
I´m afraid, that the source of my problem(s) is somewhere completely else, but probably, you have an idea, what kind of problem I should look for?
Thank you in advance,
Maria
-
wrote on 15 Apr 2011, 13:24 last edited by
Try running your program through a detector for memory problems. Or just remove the debug statement and fix the actual cause of the crash.
-
wrote on 15 Apr 2011, 14:41 last edited by
@Andre Could you give advice for such software?
-
wrote on 15 Apr 2011, 14:47 last edited by
If you're on linux then valgrind will do the job.
-
wrote on 15 Apr 2011, 14:47 last edited by
Not without you telling us what platform you're on. On linux, you could look into "valgrind":http://valgrind.org/.
-
wrote on 15 Apr 2011, 15:06 last edited by
I'm using both Windows and Linux ... two votes for valgrind is more than enough. Thank you.
Sorry for almost off-topic messages. -
wrote on 18 Apr 2011, 13:43 last edited by
Hello everyone!
I fixed my memory leak and really: The program did not crash any more (it did not crash because the RAM was full, it crashed for any other still unknown reason).
But I´m still curious: How can it be, that the single line "qDebug() << "foo"; prevents my program from crashing?
And is it the compiler optimization, that the "foo"s and "bar"s are not mixed, when I add the "bar" to the destructor?
Thanks a lot,
Maria.
-
wrote on 18 Apr 2011, 14:41 last edited by
In theory, qDebug() takes some buffer and does something for it that would otherwise make the faulty line address memory that is not usually available. Valgrind would tell exact reason for that, just use it, since you’re only one who actually has your code.
-
wrote on 19 Apr 2011, 06:07 last edited by
[quote author="Smar" date="1303137713"]In theory, qDebug() takes some buffer and does something for it that would otherwise make the faulty line address memory that is not usually available.[/quote]
This explanation is sufficient for me, thank you :)
[quote author="Smar" date="1303137713"]
Valgrind would tell exact reason for that, just use it, since you’re only one who actually has your code.
[/quote]
I´m using Windows and am to lazy to find an equivalent shy
3/9