Guest User

Untitled

a guest
Dec 9th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.41 KB | None | 0 0
  1. // Standard run:
  2. //
  3. //     $ G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=summary ./test
  4. //
  5. //     ==602== LEAK SUMMARY:
  6. //     ==602==    definitely lost: 3,000 bytes in 8 blocks
  7. //     ==602==    indirectly lost: 6,608 bytes in 208 blocks
  8. //
  9. // Comment out two lines below:
  10. //
  11. //     $ G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=summary ./test
  12. //
  13. //     ==793== LEAK SUMMARY:
  14. //     ==793==    definitely lost: 184 bytes in 2 blocks
  15. //     ==793==    indirectly lost: 240 bytes in 10 blocks
  16.  
  17.  
  18. public static int main(string[] args) {
  19.     var app = new Application();
  20.     return app.run(args);
  21. }
  22.  
  23. class Application : Gtk.Application {
  24.  
  25.     Gtk.Window window;
  26.  
  27.     construct {
  28.         application_id = "com.test";
  29.         activate.connect(on_activate);
  30.     }
  31.  
  32.     void on_activate() {
  33.         if (window != null) {
  34.             window.present();
  35.             return;
  36.         }
  37.         window = new Gtk.Window();
  38.         window.resize(300, 100);
  39.  
  40.         var toolbar = new Gtk.Toolbar();
  41.  
  42.         // COMMENT TWO LINES TO SEE MEMLEAKS DISAPPEAR
  43.         Gtk.ToolButton tb = new Gtk.ToolButton.from_stock("gtk-info");
  44.         toolbar.insert(tb, 0);
  45.  
  46.         var vbox = new Gtk.VBox(false, 0);
  47.         vbox.pack_start(toolbar, false);
  48.  
  49.         window.add(vbox);
  50.         window.show_all();
  51.  
  52.         add_window(window);
  53.     }
  54. }
Add Comment
Please, Sign In to add comment