Why would Qt inform you about a leak in C code that has nothing to do with it? Qt is set of classes, not a new language/compiler/put-whatever-you-want-here. If you leak memory in your code, use a tool for detecting memory leaks in applications, not an application development framework.
http://www.google.com/search?q=windo...leak+detection
thank you for very "informative" link and answer.
Why shouldn't Qt inform you about a leak in C code?
Check this microsoft stuff:
Is it so hard? I dont need more ;-)#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
int main(int argc, const char *argv[])
{
char* a = new char[10];
_CrtDumpMemoryLeaks();
return 0;
}
Detected memory leaks!
Dumping objects ->
...normal block at 0x00383858, 10 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD
Object dump complete.
Because it has no access to this code.
The "microsoft stuff" calls the runtime to do the job and from what I see it is specific to the .NET runtime (I might be wrong, I just had a brief look at the docs), so no real C here. It will work only when using MSVC and only in the .NET versions, so it can hardly be called portable. Qt has no access to the kernel space nor to the heap code generated by the compiler. It works strictly on the C++ layer (with exception to assembly code occuring from time to time in low-level routines). Its work ends when the compiler's work begins.Check this microsoft stuff:
So if you use MSVC.NET, call _CrtDumpMemoryLeaks() when writing Qt code. Qt will not interfere but it has nothing to help you with - you can use any features the compiler allows you to, but don't ask every possible thing to be available in Qt - it is strictly a set of C++ libraries. People tend to forget (or ignore) that which is why my response was so harsh. Besides, I had a bad day so sorry if you felt offended, I didn't mean that.
So to repeat again - Qt is not a programming language, it has no runtime, no bytecode, no intermediate execution, it doesn't extend C nor C++ language with any new features and it also doesn't limit the use of other C/C++ libraries and code and it doesn't influence alien code in any way. It is "just" a set of self-contained C++ libraries that provide you a portable API that uses and generates a standard C++ code. And it does its job (and its job only) quite well.
I gues you are wrong. It works also with vs6 which has nothing todo with .net.
Partly agree. But I think that "QT" is not only about to make things "portable", but also for RAD and according headlines on qt webpage its not just self-contained C++ libraries, but also set of development tools. It could be handy to have this basic one in the tools list as well ;-)
I have not so good understanding of heap analisys things (othervice wont post this topic here), but I think basic idea is to overload new, delete, malloc, free etc. with some heap counting code. This approach can be easily(?) implemented in qt library without any language extention. Whatever... if not such tool exist in QT, will search for external one. Not a big problem. Thanks anyway...
P.S. What personally You are using in qt development process to detect memory leaks?
You don't want a tool, you want a function and that's different. There is no point in creating a tool that does exactly the same as bunch of already existing tools. Qt Software uses Valgrind to detect memory leaks and it works great, why mimic it if it is already there?
Yes, for every possible overload. Existing and non-existing in Qt, so in practice this is not possible inside a regular library.I have not so good understanding of heap analisys things (othervice wont post this topic here), but I think basic idea is to overload new, delete, malloc, free etc. with some heap counting code.
Unfortunately not, because if you want to do it properly by substituting malloc() and free(), you have to prevent the original implementation from butting in. You can do that only by preventing the dynamic linker from loading the definition from the C runtime. On Linux this can be done by using LD_PRELOAD. But there is no way (at least I don't know one) to do it globally (meaning for all the code in tha application) by calling some C/C++ statement or passing a compiler/linker option to the compiler - you can do that for your own code, but not for the code used by 3rd party libraries you link against. That's why I said you could do leak detection in Qt-based code, but not in plain C/C++/3rd party code.This approach can be easily(?) implemented in qt library without any language extention.
If you want to substitute malloc and free, you can use mpatrol or a similar solution.Whatever... if not such tool exist in QT, will search for external one.
I don't do memory leaks - my mind seems to be sufficient to control myself. But if I really need to check for leaks, I use Valgrind, it's the best tool for the job and it does more than just detect leaks, it reports all sorts of memory related problems.P.S. What personally You are using in qt development process to detect memory leaks?
unfortunately I cannot use valgind bsc I'm using Windows XP and mingw :-(
I can control my self as well and hopefully not doing memory leaks on purpose. But if we talking about 100 000 lines of code, several developers and not well documented 3rd party libraries where is not clear who takes ownership of passed objects, than this kind of tool is highly needed.
1. Do not use M$...
2. If you can not, look for an existing memory leak tool...
3. If you do not want to.. write a new tool for yourself. It shouldn't be a big deal for you to write such a thing for debuging purposes - with support of ABI of your "specific" compiler under MinGW you should be able to provide may be also some other things..
Last edited by seim; 28th January 2009 at 19:48.
Sure you can, you can switch to Linux and develop there. Qt apps are portable, remember?
More seriously, there are similar tools for Windows (maybe not as powerful), so nothing is lost.
Try one of these: http://www.aptest.com/resources.html#app-source
Well, first of all I'm talking about my own code. Second of all documenting your own code really helps. Third of all there is not much you can do about leaks in 3rd party libraries. And fourth of all avoiding bare pointers really helps.I can control my self as well and hopefully not doing memory leaks on purpose. But if we talking about 100 000 lines of code, several developers and not well documented 3rd party libraries where is not clear who takes ownership of passed objects, than this kind of tool is highly needed.
Bookmarks