linux c 内存溢出,c++ - 如何检查Linux上的C ++ Qt应用程序中的内存泄漏? - 堆栈内存溢出...

我正在使用valgrind --leak-check=yes调试我的C ++应用程序,并且我收到了很多关于可能的内存泄漏的信息。 这是使用Qt,POSIX线程和QuantLib的C ++应用程序。 我认为信息不正确,我已经测试了它,即使应用程序是非常简单的Qt应用程序,我也得到了很多这些信息。 可能valgrind错误解释了关于Qt和POSIX线程的内存信息。

我的问题是我该怎么做,如何正确调试这个Qt应用程序,理想情况下使用valgrind,但如果可能的话可能会采用不同的方式?

==9419== Memcheck, a memory error detector

==9419== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.

==9419== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info

==9419== Command: ./qt_tradingclient_1

==9419== Parent PID: 19797

==9419==

==9419==

==9419== HEAP SUMMARY:

==9419== in use at exit: 1,587,688 bytes in 10,156 blocks

==9419== total heap usage: 365,203 allocs, 355,047 frees, 92,510,461 bytes allocated

==9419==

==9419== 1 bytes in 1 blocks are possibly lost in loss record 3 of 5,210

==9419== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)

==9419== by 0x8AC36E0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x8AD9F5B: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x88461DB: g_param_spec_string (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x1153F1B7: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x8855925: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x883DDF0: g_object_newv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x883E38B: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x1153D7DF: gtk_settings_get_for_screen (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x114EC298: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x883A5C3: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x8837406: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419==

==9419== 1 bytes in 1 blocks are possibly lost in loss record 4 of 5,210

==9419== at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)

==9419== by 0x8AC36E0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x8AD9F5B: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x88461DB: g_param_spec_string (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x114E1933: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x8855925: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x170E3225: ??? (in /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libcanberra-gtk-module.so)

==9419== by 0x170E4FB1: gtk_module_init (in /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libcanberra-gtk-module.so)

==9419== by 0x114EB7F0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x883713F: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x884854F: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419== by 0x88504AE: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3400.1)

==9419==

//还有更多,最后总结:

==9419== 32,768 bytes in 16 blocks are possibly lost in loss record 5,208 of 5,210

==9419== at 0x4C2B4F0: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)

==9419== by 0x8AC377E: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x8A931C2: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x8A93632: g_array_insert_vals (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3400.1)

==9419== by 0x1151B084: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x1151B289: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x16EBA76B: ??? (in /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/engines/libmurrine.so)

==9419== by 0x1151CBF0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x11521066: gtk_rc_get_style (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x115F2BEF: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x115F35BD: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419== by 0x115F4187: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.13)

==9419==

==9419== LEAK SUMMARY:

==9419== definitely lost: 5,759 bytes in 31 blocks

==9419== indirectly lost: 12,804 bytes in 396 blocks

==9419== possibly lost: 482,706 bytes in 2,236 blocks

==9419== still reachable: 1,086,419 bytes in 7,493 blocks

==9419== suppressed: 0 bytes in 0 blocks

==9419== Reachable blocks (those to which a pointer was found) are not shown.

==9419== To see them, rerun with: --leak-check=full --show-reachable=yes

==9419==

==9419== For counts of detected and suppressed errors, rerun with: -v

==9419== ERROR SUMMARY: 812 errors from 812 contexts (suppressed: 3 from 3)

这个问题的原因可能是程序存在堆栈溢出的情况。可以使用工具如Valgrind来检查程序的内存使用情况,以便找出问题所在。 另外,如果您想在全屏模式下使用GLX,可以使用以下步骤: 1. 打开显示设备。 2. 创建一个窗口并将其设置为全屏模式。 3. 创建一个OpenGL上下文并将其与窗口关联。 4. 绘制图形。 5. 关闭OpenGL上下文和窗口。 以下是一个简单的示例程序: ``` #include <X11/Xlib.h> #include <GL/glx.h> int main() { Display *display = XOpenDisplay(NULL); Window root = DefaultRootWindow(display); GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi = glXChooseVisual(display, 0, att); GLXContext ctx = glXCreateContext(display, vi, NULL, GL_TRUE); Colormap cmap = XCreateColormap(display, root, vi->visual, AllocNone); XSetWindowAttributes swa; swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask; Window win = XCreateWindow(display, root, 0, 0, 800, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa); XMapWindow(display, win); XStoreName(display, win, "My GLX Window"); glXMakeCurrent(display, win, ctx); // 绘制图形 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glXSwapBuffers(display, win); sleep(5); // 等待5秒钟 glXMakeCurrent(display, None, NULL); glXDestroyContext(display, ctx); XDestroyWindow(display, win); XCloseDisplay(display); return 0; } ``` 这个程序将创建一个800x600的窗口,并在其绘制一个黑色的背景。窗口将在5秒钟后关闭。请注意,此示例程序仅用于演示目的,实际应用程序可能需要更多的代码来处理输入事件、渲染3D场景等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值