node-gtk
node-gtk copied to clipboard
Look for leaks with valgrind
hi, i further examined some problems with my node-gtk app and extended the drawing area example with moving the circle arround with the mouse where i detected increasing memory and checked with valgrind - here is the result when moving the circle arround for some seconds (it seems there is also a leak by only moving the mouse) - i hope this helps: valgrind.txt
/*
* drawing-area.js
*/
const gi = require('node-gtk')
const Gtk = gi.require('Gtk', '3.0')
const Cairo = gi.require('cairo')
const Pango = gi.require('Pango')
const PangoCairo = gi.require('PangoCairo')
Gtk.init()
// Main program window
const window = new Gtk.Window({
type : Gtk.WindowType.TOPLEVEL
})
// Button
const button = Gtk.ToolButton.newFromStock(Gtk.STOCK_GO_BACK)
// Draw area
let x = 10;
let y = 10;
const drawingArea = new Gtk.DrawingArea()
drawingArea.on('draw', (_) => {
const width = drawingArea.getAllocatedWidth()
const height = drawingArea.getAllocatedHeight()
_.setSourceRgba(1, 0.0, 0.0, 1)
_.arc(x, y, 16, 0, 2 * Math.PI);
_.fill()
return true
});
drawingArea.on("button-press-event",(ev)=>{
if(
(ev.x >= (x-16)) &&
(ev.x <= (x+16)) &&
(ev.y >= (y-16)) &&
(ev.y <= (y+16))
) {
drawingArea.pressed = true;
drawingArea.queueDraw();
}
});
drawingArea.on("button-release-event",(ev)=>{
drawingArea.pressed = false;
});
drawingArea.on("motion-notify-event",(ev)=>{
//console.log(process.memoryUsage())
//console.log("motion",ev.x,ev.y);
if(drawingArea.pressed) {
x = ev.x;
y = ev.y;
drawingArea.queueDraw();
}
});
drawingArea.setEvents(drawingArea.getEvents() | (1<<8) | (1<<2) | (1<<9));
const vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL })
vbox.packStart(button, false, true, 0)
vbox.packStart(drawingArea, true, true, 0)
// configure main window
window.setDefaultSize(600, 400)
window.setResizable(true)
window.add(vbox)
// window show event
window.on('show', () => {
Gtk.main()
})
// window after-close event
window.on('destroy', () => Gtk.mainQuit())
// window close event: returning true has the semantic of preventing the default behavior:
// in this case, it would prevent the user from closing the window if we would return `true`
window.on('delete-event', () => false)
window.showAll()
Got it, thanks!