代码: 全选
#include <gtk/gtk.h>
int main(int argc, char * argv[])
{
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
/*-- Initialize GTK --*/
gtk_init(&argc, &argv);
/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*-- Display the widgets --*/
gtk_widget_show(window);
/*-- Start the GTK event loop --*/
gtk_main();
/*-- Return 0 if exit is successful --*/
return 0;
}
代码: 全选
gcc -g -o gtk main.c `pkg-config gtk+-2.0 --cflags --libs`
只好用Ctrl + C 退出
用valgrind 检测,问题更多。
valgrind ./gtk后的结果, 因无法退出,中途用Ctrl +C 退出
郁闷,还好用的是gtkmm,==10423== ERROR SUMMARY: 13 errors from 10 contexts (suppressed: 83 from 1)
==10423== malloc/free: in use at exit: 211,888 bytes in 2,684 blocks.
==10423== malloc/free: 7,720 allocs, 5,036 frees, 747,250 bytes allocated.
==10423== For counts of detected errors, rerun with: -v
==10423== searching for pointers to 2,684 not-freed blocks.
==10423== checked 487,236 bytes.
==10423==
==10423== LEAK SUMMARY:
==10423== definitely lost: 156 bytes in 11 blocks.
==10423== possibly lost: 52,520 bytes in 51 blocks.
==10423== still reachable: 159,212 bytes in 2,622 blocks.
==10423== suppressed: 0 bytes in 0 blocks.
==10423== Use --leak-check=full to see details of leaked memory.
下面是gtkmm的测试
代码: 全选
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}
问题也不少,不过可以正常返回到终端
一个简单的GTK就有这么多问题,还真是不好用,郁闷...==10546== ERROR SUMMARY: 13 errors from 11 contexts (suppressed: 101 from 1)
==10546== malloc/free: in use at exit: 285,393 bytes in 4,958 blocks.
==10546== malloc/free: 10,957 allocs, 5,999 frees, 852,248 bytes allocated.
==10546== For counts of detected errors, rerun with: -v
==10546== searching for pointers to 4,958 not-freed blocks.
==10546== checked 957,976 bytes.
==10546==
==10546== LEAK SUMMARY:
==10546== definitely lost: 156 bytes in 11 blocks.
==10546== possibly lost: 53,024 bytes in 52 blocks.
==10546== still reachable: 232,213 bytes in 4,895 blocks.
==10546== suppressed: 0 bytes in 0 blocks.
==10546== Use --leak-check=full to see details of leaked memory.