Re: Memory leak when drawing with pangomm/cairomm (MSYS2)

2021-06-25 Thread 廖骏轩 via gtkmm-list

Thanks for your suggestions! 

I have already tried removing some of the code, and the memory leak persists 
even if there’s nothing to draw. But it may be other problems elsewhere, so I 
will try to construct a minimum project later and try other things if I have 
the time.

By the way, there’s no valgrind on Windows, and I will first try without such 
tools as I don’t frequently use Windows.

> 在 2021年6月25日,下午3:26,Kjell Ahlstedt  写道:
> 
> I don't know what caused the memory leak, but I'd like to give you a few 
> suggestions for trouble-shooting.
> 
> The C++ bindings (gtkmm, pangomm, etc.) have no or extremely little code 
> that's not identical on Windows and Linux. In the first place, suspect one of 
> the underlying C modules (gtk, pango, etc.).
> 
> Do you know if there's a similar memory leak with gtkmm3? If there's no 
> memory leak with gtkmm3, suspect gtk4.
> 
> Remove more and more of the code, possibly until there's nothing left to draw 
> for queue_draw(). If the memory leak disappears at some step, you may have 
> found the function that leaks memory.
> 
> Is valgrind or a similar memory analyzer available on Windows? If so, it can 
> probably tell you who allocates a huge amount of memory.
___
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Memory leak when drawing with pangomm/cairomm (MSYS2)

2021-06-25 Thread Daniel Boles via gtkmm-list
Yeah, it's probably a C lib, and ASan or Val/MemGrind should be able to
identify leaks pretty well.
___
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Re: Memory leak when drawing with pangomm/cairomm (MSYS2)

2021-06-25 Thread Kjell Ahlstedt via gtkmm-list

Den 2021-06-22 kl. 13:38, skrev 廖骏轩 via gtkmm-list:

I have just found out that the Windows version of my project has a massive 
memory leak, while on Linux it seems alright. It uses pangomm and cairomm to 
display text, and I believe it’s similar to the examples in the online book, 
“Programming with gtkmm4”. queue_draw() is called every 100 ms, and in a few 
minutes, the memory usage would reach several GB. If I don’t call queue_draw(), 
the memory used stays around 100 MB.
Does anyone know what caused the memory leak? Thanks!


I don't know what caused the memory leak, but I'd like to give you a few 
suggestions for trouble-shooting.


The C++ bindings (gtkmm, pangomm, etc.) have no or extremely little code 
that's not identical on Windows and Linux. In the first place, suspect 
one of the underlying C modules (gtk, pango, etc.).


Do you know if there's a similar memory leak with gtkmm3? If there's no 
memory leak with gtkmm3, suspect gtk4.


Remove more and more of the code, possibly until there's nothing left to 
draw for queue_draw(). If the memory leak disappears at some step, you 
may have found the function that leaks memory.


Is valgrind or a similar memory analyzer available on Windows? If so, it 
can probably tell you who allocates a huge amount of memory.


___
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Memory leak when drawing with pangomm/cairomm (MSYS2)

2021-06-22 Thread 廖骏轩 via gtkmm-list


I have just found out that the Windows version of my project has a massive 
memory leak, while on Linux it seems alright. It uses pangomm and cairomm to 
display text, and I believe it’s similar to the examples in the online book, 
“Programming with gtkmm4”. queue_draw() is called every 100 ms, and in a few 
minutes, the memory usage would reach several GB. If I don’t call queue_draw(), 
the memory used stays around 100 MB.
Does anyone know what caused the memory leak? Thanks!
Here is what the code looks like:
--
#include "KbiDraw.h"
#include 
#include 


KbiDraw::KbiDraw(Player* p_player)
        :
        player(p_player)
{
    set_content_width(300);
    set_content_height(300);
    set_expand(true);
    set_draw_func(sigc::mem_fun(*this, &KbiDraw::on_draw));
    Glib::signal_timeout().connect(sigc::mem_fun(*this, &KbiDraw::refresh), 
100);
}


KbiDraw::~KbiDraw()
= default;


void KbiDraw::on_draw(const Cairo::RefPtr& cr, int width, int 
height)
{




    // Draw a black rectangle
    cr->set_source_rgb(0.0, 0.0, 0.0);
    draw_rectangle(cr, width, height);


    // and some white text
    cr->set_source_rgb(1.0, 1.0, 1.0);
    draw_text(cr, width, height);


    Cairo::Matrix matrix(1.0, 0.0, 0.0, -1.0, 0.0, height);


    // apply the matrix
    cr->transform(matrix);


}


void KbiDraw::draw_rectangle(const Cairo::RefPtr& cr, int 
width, int height)
{


    cr->rectangle(0, 0, width, height);
    cr->fill();


}


void KbiDraw::draw_text(const Cairo::RefPtr& cr, int 
rectangle_width, int rectangle_height)
{


    Pango::FontDescription font;


    font.set_family("Serif");
    font.set_weight(Pango::Weight::BOLD);
    font.set_size(35000);


    std::stringstream draw_note;
    auto current_notes = player->get_current_notes();
    for (const auto& note : current_notes) {
        draw_note << note << " ";
    }


    auto layout = create_pango_layout(draw_note.str());
    layout->set_font_description(font);


    int text_width;
    int text_height;


    //get the text dimensions (it updates the variables -- by reference)
    layout->get_pixel_size(text_width, text_height);


    // Position the text in the middle
    cr->move_to((rectangle_width - text_width)/2, (rectangle_height - 
text_height)/2);


    layout->show_in_cairo_context(cr);


}


bool KbiDraw::refresh()
{
    queue_draw();
    return true;
}
--
___
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Memory leak when drawing with pangomm/cairomm (MSYS2)

2021-06-22 Thread 廖骏轩 via gtkmm-list
I have just found out that the Windows version of my project has a massive 
memory leak, while on Linux it seems alright. It uses pangomm and cairomm to 
display text, and I believe it’s similar to the examples in the online book, 
“Programming with gtkmm4”. queue_draw() is called every 100 ms, and in a few 
minutes the memory usage would reach several GB. If I don’t call queue_draw(), 
the memory used stays around 100 MB.
___
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list